Loading lib/base64.c +16 −6 Original line number Diff line number Diff line Loading @@ -76,10 +76,10 @@ static void decodeQuantum(unsigned char *dest, const char *src) /* * Curl_base64_decode() * * Given a base64 string at src, decode it into the memory pointed to by * dest. Returns the length of the decoded data. * Given a base64 string at src, decode it and return an allocated memory in * the *outptr. Returns the length of the decoded data. */ size_t Curl_base64_decode(const char *src, char *dest) size_t Curl_base64_decode(const char *src, unsigned char **outptr) { int length = 0; int equalsTerm = 0; Loading @@ -87,6 +87,9 @@ size_t Curl_base64_decode(const char *src, char *dest) int numQuantums; unsigned char lastQuantum[3]; size_t rawlen=0; unsigned char *newstr; *outptr = NULL; while((src[length] != '=') && src[length]) length++; Loading @@ -97,15 +100,22 @@ size_t Curl_base64_decode(const char *src, char *dest) rawlen = (numQuantums * 3) - equalsTerm; newstr = malloc(rawlen+1); if(!newstr) return 0; *outptr = newstr; for(i = 0; i < numQuantums - 1; i++) { decodeQuantum((unsigned char *)dest, src); dest += 3; src += 4; decodeQuantum((unsigned char *)newstr, src); newstr += 3; src += 4; } decodeQuantum(lastQuantum, src); for(i = 0; i < 3 - equalsTerm; i++) dest[i] = lastQuantum[i]; newstr[i] = lastQuantum[i]; newstr[i] = 0; /* zero terminate */ return rawlen; } Loading lib/base64.h +1 −1 Original line number Diff line number Diff line Loading @@ -23,5 +23,5 @@ * $Id$ ***************************************************************************/ size_t Curl_base64_encode(const char *input, size_t size, char **str); size_t Curl_base64_decode(const char *source, char *dest); size_t Curl_base64_decode(const char *source, unsigned char **outptr); #endif lib/http_negotiate.c +1 −6 Original line number Diff line number Diff line Loading @@ -166,12 +166,7 @@ int Curl_input_negotiate(struct connectdata *conn, char *header) len = strlen(header); if (len > 0) { int rawlen; input_token.length = (len+3)/4 * 3; input_token.value = malloc(input_token.length); if (input_token.value == NULL) return ENOMEM; rawlen = Curl_base64_decode(header, input_token.value); int rawlen = Curl_base64_decode(header, &input_token.value); if (rawlen < 0) return -1; input_token.length = rawlen; Loading lib/http_ntlm.c +4 −4 Original line number Diff line number Diff line Loading @@ -123,17 +123,17 @@ CURLntlm Curl_input_ntlm(struct connectdata *conn, 32 (48) start of data block */ size_t size; unsigned char *buffer = (unsigned char *)malloc(strlen(header)); if (buffer == NULL) unsigned char *buffer; size = Curl_base64_decode(header, &buffer); if(!buffer) return CURLNTLM_BAD; size = Curl_base64_decode(header, (char *)buffer); ntlm->state = NTLMSTATE_TYPE2; /* we got a type-2 */ if(size >= 48) /* the nonce of interest is index [24 .. 31], 8 bytes */ memcpy(ntlm->nonce, &buffer[24], 8); /* FIX: add an else here! */ /* at index decimal 20, there's a 32bit NTLM flag field */ Loading lib/krb4.c +18 −4 Original line number Diff line number Diff line Loading @@ -199,6 +199,7 @@ krb4_auth(void *app_data, struct connectdata *conn) { int ret; char *p; unsigned char *ptr; int len; KTEXT_ST adat; MSG_DAT msg_data; Loading Loading @@ -275,11 +276,17 @@ krb4_auth(void *app_data, struct connectdata *conn) return AUTH_ERROR; } p += 5; len = Curl_base64_decode(p, (char *)adat.dat); if(len < 0) { len = Curl_base64_decode(p, &ptr); if(len > sizeof(adat.dat)-1) { free(ptr); len=0; } if(!len || !ptr) { Curl_failf(data, "Failed to decode base64 from server"); return AUTH_ERROR; } memcpy((char *)adat.dat, ptr, len); free(ptr); adat.length = len; ret = krb_rd_safe(adat.dat, adat.length, &d->key, (struct sockaddr_in *)hisctladdr, Loading Loading @@ -321,6 +328,7 @@ CURLcode Curl_krb_kauth(struct connectdata *conn) ssize_t nread; int save; CURLcode result; unsigned char *ptr; save = Curl_set_command_prot(conn, prot_private); Loading @@ -346,12 +354,18 @@ CURLcode Curl_krb_kauth(struct connectdata *conn) } p += 2; tmp = Curl_base64_decode(p, (char *)tkt.dat); if(tmp < 0) { tmp = Curl_base64_decode(p, &ptr); if(len > sizeof(tkt.dat)-1) { free(ptr); len=0; } if(!len || !ptr) { Curl_failf(conn->data, "Failed to decode base64 in reply.\n"); Curl_set_command_prot(conn, save); return CURLE_FTP_WEIRD_SERVER_REPLY; } memcpy((char *)tkt.dat, ptr, tmp); free(ptr); tkt.length = tmp; tktcopy.length = tkt.length; Loading Loading
lib/base64.c +16 −6 Original line number Diff line number Diff line Loading @@ -76,10 +76,10 @@ static void decodeQuantum(unsigned char *dest, const char *src) /* * Curl_base64_decode() * * Given a base64 string at src, decode it into the memory pointed to by * dest. Returns the length of the decoded data. * Given a base64 string at src, decode it and return an allocated memory in * the *outptr. Returns the length of the decoded data. */ size_t Curl_base64_decode(const char *src, char *dest) size_t Curl_base64_decode(const char *src, unsigned char **outptr) { int length = 0; int equalsTerm = 0; Loading @@ -87,6 +87,9 @@ size_t Curl_base64_decode(const char *src, char *dest) int numQuantums; unsigned char lastQuantum[3]; size_t rawlen=0; unsigned char *newstr; *outptr = NULL; while((src[length] != '=') && src[length]) length++; Loading @@ -97,15 +100,22 @@ size_t Curl_base64_decode(const char *src, char *dest) rawlen = (numQuantums * 3) - equalsTerm; newstr = malloc(rawlen+1); if(!newstr) return 0; *outptr = newstr; for(i = 0; i < numQuantums - 1; i++) { decodeQuantum((unsigned char *)dest, src); dest += 3; src += 4; decodeQuantum((unsigned char *)newstr, src); newstr += 3; src += 4; } decodeQuantum(lastQuantum, src); for(i = 0; i < 3 - equalsTerm; i++) dest[i] = lastQuantum[i]; newstr[i] = lastQuantum[i]; newstr[i] = 0; /* zero terminate */ return rawlen; } Loading
lib/base64.h +1 −1 Original line number Diff line number Diff line Loading @@ -23,5 +23,5 @@ * $Id$ ***************************************************************************/ size_t Curl_base64_encode(const char *input, size_t size, char **str); size_t Curl_base64_decode(const char *source, char *dest); size_t Curl_base64_decode(const char *source, unsigned char **outptr); #endif
lib/http_negotiate.c +1 −6 Original line number Diff line number Diff line Loading @@ -166,12 +166,7 @@ int Curl_input_negotiate(struct connectdata *conn, char *header) len = strlen(header); if (len > 0) { int rawlen; input_token.length = (len+3)/4 * 3; input_token.value = malloc(input_token.length); if (input_token.value == NULL) return ENOMEM; rawlen = Curl_base64_decode(header, input_token.value); int rawlen = Curl_base64_decode(header, &input_token.value); if (rawlen < 0) return -1; input_token.length = rawlen; Loading
lib/http_ntlm.c +4 −4 Original line number Diff line number Diff line Loading @@ -123,17 +123,17 @@ CURLntlm Curl_input_ntlm(struct connectdata *conn, 32 (48) start of data block */ size_t size; unsigned char *buffer = (unsigned char *)malloc(strlen(header)); if (buffer == NULL) unsigned char *buffer; size = Curl_base64_decode(header, &buffer); if(!buffer) return CURLNTLM_BAD; size = Curl_base64_decode(header, (char *)buffer); ntlm->state = NTLMSTATE_TYPE2; /* we got a type-2 */ if(size >= 48) /* the nonce of interest is index [24 .. 31], 8 bytes */ memcpy(ntlm->nonce, &buffer[24], 8); /* FIX: add an else here! */ /* at index decimal 20, there's a 32bit NTLM flag field */ Loading
lib/krb4.c +18 −4 Original line number Diff line number Diff line Loading @@ -199,6 +199,7 @@ krb4_auth(void *app_data, struct connectdata *conn) { int ret; char *p; unsigned char *ptr; int len; KTEXT_ST adat; MSG_DAT msg_data; Loading Loading @@ -275,11 +276,17 @@ krb4_auth(void *app_data, struct connectdata *conn) return AUTH_ERROR; } p += 5; len = Curl_base64_decode(p, (char *)adat.dat); if(len < 0) { len = Curl_base64_decode(p, &ptr); if(len > sizeof(adat.dat)-1) { free(ptr); len=0; } if(!len || !ptr) { Curl_failf(data, "Failed to decode base64 from server"); return AUTH_ERROR; } memcpy((char *)adat.dat, ptr, len); free(ptr); adat.length = len; ret = krb_rd_safe(adat.dat, adat.length, &d->key, (struct sockaddr_in *)hisctladdr, Loading Loading @@ -321,6 +328,7 @@ CURLcode Curl_krb_kauth(struct connectdata *conn) ssize_t nread; int save; CURLcode result; unsigned char *ptr; save = Curl_set_command_prot(conn, prot_private); Loading @@ -346,12 +354,18 @@ CURLcode Curl_krb_kauth(struct connectdata *conn) } p += 2; tmp = Curl_base64_decode(p, (char *)tkt.dat); if(tmp < 0) { tmp = Curl_base64_decode(p, &ptr); if(len > sizeof(tkt.dat)-1) { free(ptr); len=0; } if(!len || !ptr) { Curl_failf(conn->data, "Failed to decode base64 in reply.\n"); Curl_set_command_prot(conn, save); return CURLE_FTP_WEIRD_SERVER_REPLY; } memcpy((char *)tkt.dat, ptr, tmp); free(ptr); tkt.length = tmp; tktcopy.length = tkt.length; Loading