diff options
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | libbb/uuencode.c | 29 | ||||
-rw-r--r-- | networking/httpd.c | 6 |
3 files changed, 19 insertions, 20 deletions
diff --git a/include/libbb.h b/include/libbb.h index ef4a34f07..e56fff3e8 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -2035,8 +2035,8 @@ enum { /* Sign-extends to a value which never matches fgetc result: */ BASE64_FLAG_NO_STOP_CHAR = 0x80, }; -const char *decode_base64(char **pp_dst, const char *src) FAST_FUNC; -const char *decode_base32(char **pp_dst, const char *src) FAST_FUNC; +char *decode_base64(char *dst, const char **pp_src) FAST_FUNC; +char *decode_base32(char *dst, const char **pp_src) FAST_FUNC; void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; typedef struct md5_ctx_t { diff --git a/libbb/uuencode.c b/libbb/uuencode.c index 139c60bd5..6e63bfc6a 100644 --- a/libbb/uuencode.c +++ b/libbb/uuencode.c @@ -86,9 +86,9 @@ void FAST_FUNC bb_uuencode(char *p, const void *src, int length, const char *tbl * If points to '\0', then the source was fully decoded. * (*pp_dst): advanced past the last written byte. */ -const char* FAST_FUNC decode_base64(char **pp_dst, const char *src) +char* FAST_FUNC decode_base64(char *dst, const char **pp_src) { - char *dst = *pp_dst; + const char *src = pp_src ? *pp_src : dst; /* for httpd.c, support NULL 2nd param */ unsigned ch = 0; unsigned t; int i = 0; @@ -129,16 +129,17 @@ const char* FAST_FUNC decode_base64(char **pp_dst, const char *src) ch = 0; } } - *pp_dst = dst; /* i is zero here if full 4-char block was decoded */ - return src - i; /* -i rejects truncations: e.g. "MQ" and "MQ=" (correct encoding is "MQ==" -> "1") */ + if (pp_src) + *pp_src = src - i; /* -i rejects truncations: e.g. "MQ" and "MQ=" (correct encoding is "MQ==" -> "1") */ + return dst; } #if ENABLE_BASE32 -const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) +char* FAST_FUNC decode_base32(char *dst, const char **pp_src) { - char *dst = *pp_dst; - int64_t ch = 0; + const char *src = *pp_src; + uint64_t ch = 0; unsigned t; int i = 0; @@ -169,9 +170,9 @@ const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) *dst++ = (char) ch; } } - *pp_dst = dst; /* i is zero here if full 8-char block was decoded */ - return src - i; + *pp_src = src - i; + return dst; tail: { const char *s = src; @@ -192,8 +193,8 @@ const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) *dst++ = (char) ch; dst -= (i+1) * 2 / 3; /* discard last 1, 2, 3 or 4 bytes */ } - *pp_dst = dst; - return src; + *pp_src = src; + return dst; } #endif @@ -249,13 +250,13 @@ void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags) if (uu_style_end && strcmp(buf, "====") == 0) return; - out_tail = buf; + in_tail = buf; #if ENABLE_BASE32 if (base32) - in_tail = decode_base32(&out_tail, buf); + out_tail = decode_base32(buf, &in_tail); else #endif - in_tail = decode_base64(&out_tail, buf); + out_tail = decode_base64(buf, &in_tail); fwrite(buf, (out_tail - buf), 1, dst_stream); diff --git a/networking/httpd.c b/networking/httpd.c index 4ffd89c48..4346141ee 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -1015,11 +1015,9 @@ static char *encodeString(const char *string) * Parameter: a pointer to a base64 encoded string. * Decoded data is stored in-place. */ -static void decodeBase64(char *Data) +static void decodeBase64(char *data) { - char *eptr = Data; - decode_base64(&eptr, Data); - *eptr = '\0'; + decode_base64(data, NULL)[0] = '\0'; } #endif |