aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-11-28 13:26:44 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-11-28 13:27:36 +0100
commit885121e25db2ec9a8191a406085d91790a133d20 (patch)
treeaa5c89af1b273c618bef11b836de38788007b4c9
parentfc6faac84e978c9482106f53e711ab971a0ce188 (diff)
downloadbusybox-w32-885121e25db2ec9a8191a406085d91790a133d20.tar.gz
busybox-w32-885121e25db2ec9a8191a406085d91790a133d20.tar.bz2
busybox-w32-885121e25db2ec9a8191a406085d91790a133d20.zip
libbb: change decode_base32/64 API to return the end of _dst_, not _src_.
function old new delta decode_base64 173 178 +5 read_base64 222 220 -2 decode_base32 186 182 -4 handle_incoming_and_exit 2263 2239 -24 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 5/-30) Total: -25 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h4
-rw-r--r--libbb/uuencode.c29
-rw-r--r--networking/httpd.c6
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 {
2035 /* Sign-extends to a value which never matches fgetc result: */ 2035 /* Sign-extends to a value which never matches fgetc result: */
2036 BASE64_FLAG_NO_STOP_CHAR = 0x80, 2036 BASE64_FLAG_NO_STOP_CHAR = 0x80,
2037}; 2037};
2038const char *decode_base64(char **pp_dst, const char *src) FAST_FUNC; 2038char *decode_base64(char *dst, const char **pp_src) FAST_FUNC;
2039const char *decode_base32(char **pp_dst, const char *src) FAST_FUNC; 2039char *decode_base32(char *dst, const char **pp_src) FAST_FUNC;
2040void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; 2040void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC;
2041 2041
2042typedef struct md5_ctx_t { 2042typedef 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
86 * If points to '\0', then the source was fully decoded. 86 * If points to '\0', then the source was fully decoded.
87 * (*pp_dst): advanced past the last written byte. 87 * (*pp_dst): advanced past the last written byte.
88 */ 88 */
89const char* FAST_FUNC decode_base64(char **pp_dst, const char *src) 89char* FAST_FUNC decode_base64(char *dst, const char **pp_src)
90{ 90{
91 char *dst = *pp_dst; 91 const char *src = pp_src ? *pp_src : dst; /* for httpd.c, support NULL 2nd param */
92 unsigned ch = 0; 92 unsigned ch = 0;
93 unsigned t; 93 unsigned t;
94 int i = 0; 94 int i = 0;
@@ -129,16 +129,17 @@ const char* FAST_FUNC decode_base64(char **pp_dst, const char *src)
129 ch = 0; 129 ch = 0;
130 } 130 }
131 } 131 }
132 *pp_dst = dst;
133 /* i is zero here if full 4-char block was decoded */ 132 /* i is zero here if full 4-char block was decoded */
134 return src - i; /* -i rejects truncations: e.g. "MQ" and "MQ=" (correct encoding is "MQ==" -> "1") */ 133 if (pp_src)
134 *pp_src = src - i; /* -i rejects truncations: e.g. "MQ" and "MQ=" (correct encoding is "MQ==" -> "1") */
135 return dst;
135} 136}
136 137
137#if ENABLE_BASE32 138#if ENABLE_BASE32
138const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) 139char* FAST_FUNC decode_base32(char *dst, const char **pp_src)
139{ 140{
140 char *dst = *pp_dst; 141 const char *src = *pp_src;
141 int64_t ch = 0; 142 uint64_t ch = 0;
142 unsigned t; 143 unsigned t;
143 int i = 0; 144 int i = 0;
144 145
@@ -169,9 +170,9 @@ const char* FAST_FUNC decode_base32(char **pp_dst, const char *src)
169 *dst++ = (char) ch; 170 *dst++ = (char) ch;
170 } 171 }
171 } 172 }
172 *pp_dst = dst;
173 /* i is zero here if full 8-char block was decoded */ 173 /* i is zero here if full 8-char block was decoded */
174 return src - i; 174 *pp_src = src - i;
175 return dst;
175 tail: 176 tail:
176 { 177 {
177 const char *s = src; 178 const char *s = src;
@@ -192,8 +193,8 @@ const char* FAST_FUNC decode_base32(char **pp_dst, const char *src)
192 *dst++ = (char) ch; 193 *dst++ = (char) ch;
193 dst -= (i+1) * 2 / 3; /* discard last 1, 2, 3 or 4 bytes */ 194 dst -= (i+1) * 2 / 3; /* discard last 1, 2, 3 or 4 bytes */
194 } 195 }
195 *pp_dst = dst; 196 *pp_src = src;
196 return src; 197 return dst;
197} 198}
198#endif 199#endif
199 200
@@ -249,13 +250,13 @@ void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags)
249 if (uu_style_end && strcmp(buf, "====") == 0) 250 if (uu_style_end && strcmp(buf, "====") == 0)
250 return; 251 return;
251 252
252 out_tail = buf; 253 in_tail = buf;
253#if ENABLE_BASE32 254#if ENABLE_BASE32
254 if (base32) 255 if (base32)
255 in_tail = decode_base32(&out_tail, buf); 256 out_tail = decode_base32(buf, &in_tail);
256 else 257 else
257#endif 258#endif
258 in_tail = decode_base64(&out_tail, buf); 259 out_tail = decode_base64(buf, &in_tail);
259 260
260 fwrite(buf, (out_tail - buf), 1, dst_stream); 261 fwrite(buf, (out_tail - buf), 1, dst_stream);
261 262
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)
1015 * Parameter: a pointer to a base64 encoded string. 1015 * Parameter: a pointer to a base64 encoded string.
1016 * Decoded data is stored in-place. 1016 * Decoded data is stored in-place.
1017 */ 1017 */
1018static void decodeBase64(char *Data) 1018static void decodeBase64(char *data)
1019{ 1019{
1020 char *eptr = Data; 1020 decode_base64(data, NULL)[0] = '\0';
1021 decode_base64(&eptr, Data);
1022 *eptr = '\0';
1023} 1021}
1024#endif 1022#endif
1025 1023