aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-27 21:40:07 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-27 21:40:07 +0000
commit12d2129d500ed93a331c5a9863dd56f5dd0235e9 (patch)
tree599729b4538ec366f940b7dce112522df3770106
parentc965f4b14194ade82c9f30807fa948d6545e55d6 (diff)
downloadbusybox-w32-12d2129d500ed93a331c5a9863dd56f5dd0235e9.tar.gz
busybox-w32-12d2129d500ed93a331c5a9863dd56f5dd0235e9.tar.bz2
busybox-w32-12d2129d500ed93a331c5a9863dd56f5dd0235e9.zip
wget: fix bug in base64 encoding (bug 1404). +10 bytes.
-rw-r--r--networking/wget.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/networking/wget.c b/networking/wget.c
index bd9480ce5..19ff792ed 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -42,25 +42,27 @@ enum {
42 STALLTIME = 5 /* Seconds when xfer considered "stalled" */ 42 STALLTIME = 5 /* Seconds when xfer considered "stalled" */
43}; 43};
44#else 44#else
45static void progressmeter(int flag) {} 45static ALWAYS_INLINE void progressmeter(int flag) {}
46#endif 46#endif
47 47
48/* Read NMEMB elements of SIZE bytes into PTR from STREAM. Returns the 48/* Read NMEMB bytes into PTR from STREAM. Returns the number of bytes read,
49 * number of elements read, and a short count if an eof or non-interrupt 49 * and a short count if an eof or non-interrupt error is encountered. */
50 * error is encountered. */ 50static size_t safe_fread(void *ptr, size_t nmemb, FILE *stream)
51static size_t safe_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
52{ 51{
53 size_t ret = 0; 52 size_t ret;
53 char *p = (char*)ptr;
54 54
55 do { 55 do {
56 clearerr(stream); 56 clearerr(stream);
57 ret += fread((char *)ptr + (ret * size), size, nmemb - ret, stream); 57 ret = fread(p, 1, nmemb, stream);
58 } while (ret < nmemb && ferror(stream) && errno == EINTR); 58 p += ret;
59 nmemb -= ret;
60 } while (nmemb && ferror(stream) && errno == EINTR);
59 61
60 return ret; 62 return p - (char*)ptr;
61} 63}
62 64
63/* Read a line or SIZE - 1 bytes into S, whichever is less, from STREAM. 65/* Read a line or SIZE-1 bytes into S, whichever is less, from STREAM.
64 * Returns S, or NULL if an eof or non-interrupt error is encountered. */ 66 * Returns S, or NULL if an eof or non-interrupt error is encountered. */
65static char *safe_fgets(char *s, int size, FILE *stream) 67static char *safe_fgets(char *s, int size, FILE *stream)
66{ 68{
@@ -75,10 +77,13 @@ static char *safe_fgets(char *s, int size, FILE *stream)
75} 77}
76 78
77#if ENABLE_FEATURE_WGET_AUTHENTICATION 79#if ENABLE_FEATURE_WGET_AUTHENTICATION
78/* Base64-encode character string and return the string. */ 80/* Base64-encode character string. buf is assumed to be char buf[512]. */
79static char *base64enc(const unsigned char *p, char *buf, int len) 81static char *base64enc_512(char buf[512], const char *str)
80{ 82{
81 bb_uuencode(buf, p, len, bb_uuenc_tbl_base64); 83 unsigned len = strlen(str);
84 if (len > 512/4*3 - 10) /* paranoia */
85 len = 512/4*3 - 10;
86 bb_uuencode(buf, str, len, bb_uuenc_tbl_base64);
82 return buf; 87 return buf;
83} 88}
84#endif 89#endif
@@ -265,12 +270,12 @@ int wget_main(int argc, char **argv)
265 270
266#if ENABLE_FEATURE_WGET_AUTHENTICATION 271#if ENABLE_FEATURE_WGET_AUTHENTICATION
267 if (target.user) { 272 if (target.user) {
268 fprintf(sfp, "Authorization: Basic %s\r\n", 273 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n"+6,
269 base64enc((unsigned char*)target.user, buf, sizeof(buf))); 274 base64enc_512(buf, target.user));
270 } 275 }
271 if (use_proxy && server.user) { 276 if (use_proxy && server.user) {
272 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n", 277 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n",
273 base64enc((unsigned char*)server.user, buf, sizeof(buf))); 278 base64enc_512(buf, server.user));
274 } 279 }
275#endif 280#endif
276 281
@@ -459,7 +464,7 @@ int wget_main(int argc, char **argv)
459 unsigned rdsz = sizeof(buf); 464 unsigned rdsz = sizeof(buf);
460 if (content_len < sizeof(buf) && (chunked || got_clen)) 465 if (content_len < sizeof(buf) && (chunked || got_clen))
461 rdsz = (unsigned)content_len; 466 rdsz = (unsigned)content_len;
462 n = safe_fread(buf, 1, rdsz, dfp); 467 n = safe_fread(buf, rdsz, dfp);
463 if (n <= 0) 468 if (n <= 0)
464 break; 469 break;
465 if (full_write(output_fd, buf, n) != n) { 470 if (full_write(output_fd, buf, n) != n) {
@@ -775,7 +780,7 @@ progressmeter(int flag)
775 putc('\n', stderr); 780 putc('\n', stderr);
776 } 781 }
777} 782}
778#endif 783#endif /* FEATURE_WGET_STATUSBAR */
779 784
780/* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff, 785/* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff,
781 * much of which was blatantly stolen from openssh. */ 786 * much of which was blatantly stolen from openssh. */