1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-10 11:35:07 -05:00

security.c: Curl_sec_read_msg tweaks

- Renamed the variables name to better match their intend.
- Unified the |decoded_len| checks.
- Added some FIXMEs to flag some improvement that did not go in this
  change.
This commit is contained in:
Julien Chaffraix 2010-09-12 16:08:52 -07:00 committed by Daniel Stenberg
parent d23c59ecfc
commit 7d4f8c2809

View File

@ -348,40 +348,48 @@ static ssize_t _sec_send(struct connectdata *conn, int num,
return sec_write(conn, fd, buffer, length); return sec_write(conn, fd, buffer, length);
} }
int /* FIXME: |level| should not be an int but a struct protection_level */
Curl_sec_read_msg(struct connectdata *conn, char *s, int level) int Curl_sec_read_msg(struct connectdata *conn, char *buffer, int level)
{ {
int len; /* decoded_len should be size_t or ssize_t but conn->mech->decode returns an
unsigned char *buf; int */
int code; int decoded_len;
char *buf;
int ret_code;
len = Curl_base64_decode(s + 4, &buf); /* XXX */ decoded_len = Curl_base64_decode(buffer + 4, (unsigned char **)&buf);
if(len > 0) if(decoded_len <= 0) {
len = (conn->mech->decode)(conn->app_data, buf, len, level, conn); free(buf);
else
return -1; return -1;
}
if(len < 0) { decoded_len = (conn->mech->decode)(conn->app_data, buf, decoded_len,
level, conn);
if(decoded_len <= 0) {
free(buf); free(buf);
return -1; return -1;
} }
if(conn->data->set.verbose) { if(conn->data->set.verbose) {
buf[len] = '\n'; buf[decoded_len] = '\n';
Curl_debug(conn->data, CURLINFO_HEADER_IN, (char *)buf, len + 1, conn); Curl_debug(conn->data, CURLINFO_HEADER_IN, buf, decoded_len + 1, conn);
} }
buf[len] = '\0'; buf[decoded_len] = '\0';
DEBUGASSERT(decoded_len > 3);
if(buf[3] == '-') if(buf[3] == '-')
code = 0; ret_code = 0;
else else {
sscanf((char *)buf, "%d", &code); /* Check for error? */
if(buf[len-1] == '\n') sscanf(buf, "%d", &ret_code);
buf[len-1] = '\0'; }
strcpy(s, (char *)buf);
if(buf[decoded_len - 1] == '\n')
buf[decoded_len - 1] = '\0';
/* FIXME: Is |buffer| length always greater than |decoded_len|? */
strcpy(buffer, buf);
free(buf); free(buf);
return code; return ret_code;
} }
enum protection_level enum protection_level