summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2024-11-21 15:40:23 -0600
committerAlexander M Pickering <alex@cogarr.net>2024-11-21 15:40:23 -0600
commit5cc677721caa0fc1df9002b0ceba4a3452a37b6c (patch)
treebed7c8fab25721ac22759f6e309b363bf72a4455
parent8d548d7a67b7037ebac6388ab8d6b0477f2b28a1 (diff)
downloadbusybox-w32-packaging-5cc677721caa0fc1df9002b0ceba4a3452a37b6c.tar.gz
busybox-w32-packaging-5cc677721caa0fc1df9002b0ceba4a3452a37b6c.tar.bz2
busybox-w32-packaging-5cc677721caa0fc1df9002b0ceba4a3452a37b6c.zip
Fix memory leak
-rw-r--r--libressl.patch43
1 files changed, 25 insertions, 18 deletions
diff --git a/libressl.patch b/libressl.patch
index 4953f41..bfd3d20 100644
--- a/libressl.patch
+++ b/libressl.patch
@@ -102,7 +102,7 @@ index 9f1dd67ec..60e1afe99 100644
102 static void tls_xwrite(tls_state_t *tls, int len) 102 static void tls_xwrite(tls_state_t *tls, int len)
103 { 103 {
104diff --git a/networking/wget.c b/networking/wget.c 104diff --git a/networking/wget.c b/networking/wget.c
105index 6a64836fb..831bc4023 100644 105index 6a64836fb..ad352586e 100644
106--- a/networking/wget.c 106--- a/networking/wget.c
107+++ b/networking/wget.c 107+++ b/networking/wget.c
108@@ -1,4 +1,3 @@ 108@@ -1,4 +1,3 @@
@@ -120,7 +120,7 @@ index 6a64836fb..831bc4023 100644
120 #if ENABLE_FEATURE_WGET_TIMEOUT 120 #if ENABLE_FEATURE_WGET_TIMEOUT
121 unsigned timeout_seconds; 121 unsigned timeout_seconds;
122 smallint die_if_timed_out; 122 smallint die_if_timed_out;
123@@ -460,6 +462,67 @@ static FILE *open_socket(len_and_sockaddr *lsa) 123@@ -460,6 +462,68 @@ static FILE *open_socket(len_and_sockaddr *lsa)
124 return fp; 124 return fp;
125 } 125 }
126 126
@@ -182,13 +182,14 @@ index 6a64836fb..831bc4023 100644
182+ tls_config_set_ca_mem(cfg, pemmem, pemsize); 182+ tls_config_set_ca_mem(cfg, pemmem, pemsize);
183+ fclose(pemfile); 183+ fclose(pemfile);
184+ DeleteFileA(tmpfilename); 184+ DeleteFileA(tmpfilename);
185+ return pemmem;
185+} 186+}
186+#endif 187+#endif
187+ 188+
188 /* We balk at any control chars in other side's messages. 189 /* We balk at any control chars in other side's messages.
189 * This prevents nasty surprises (e.g. ESC sequences) in "Location:" URLs 190 * This prevents nasty surprises (e.g. ESC sequences) in "Location:" URLs
190 * and error messages. 191 * and error messages.
191@@ -689,6 +752,7 @@ static void reset_beg_range_to_zero(void) 192@@ -689,6 +753,7 @@ static void reset_beg_range_to_zero(void)
192 } 193 }
193 194
194 #if ENABLE_FEATURE_WGET_OPENSSL 195 #if ENABLE_FEATURE_WGET_OPENSSL
@@ -196,7 +197,7 @@ index 6a64836fb..831bc4023 100644
196 static int spawn_https_helper_openssl(const char *host, unsigned port) 197 static int spawn_https_helper_openssl(const char *host, unsigned port)
197 { 198 {
198 char *allocated = NULL; 199 char *allocated = NULL;
199@@ -698,7 +762,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 200@@ -698,7 +763,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
200 IF_FEATURE_WGET_HTTPS(volatile int child_failed = 0;) 201 IF_FEATURE_WGET_HTTPS(volatile int child_failed = 0;)
201 202
202 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0) 203 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp) != 0)
@@ -205,7 +206,7 @@ index 6a64836fb..831bc4023 100644
205 bb_simple_perror_msg_and_die("socketpair"); 206 bb_simple_perror_msg_and_die("socketpair");
206 207
207 if (!strchr(host, ':')) 208 if (!strchr(host, ':'))
208@@ -709,18 +773,18 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 209@@ -709,18 +774,18 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
209 fflush_all(); 210 fflush_all();
210 pid = xvfork(); 211 pid = xvfork();
211 if (pid == 0) { 212 if (pid == 0) {
@@ -230,7 +231,7 @@ index 6a64836fb..831bc4023 100644
230 xmove_fd(2, 3); 231 xmove_fd(2, 3);
231 xopen("/dev/null", O_RDWR); 232 xopen("/dev/null", O_RDWR);
232 memset(&argv, 0, sizeof(argv)); 233 memset(&argv, 0, sizeof(argv));
233@@ -729,18 +793,18 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 234@@ -729,18 +794,18 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
234 argv[2] = (char*)"-quiet"; 235 argv[2] = (char*)"-quiet";
235 argv[3] = (char*)"-connect"; 236 argv[3] = (char*)"-connect";
236 argv[4] = (char*)host; 237 argv[4] = (char*)host;
@@ -255,7 +256,7 @@ index 6a64836fb..831bc4023 100644
255 *argp++ = (char*)"-verify"; //[7] 256 *argp++ = (char*)"-verify"; //[7]
256 *argp++ = (char*)"100"; //[8] 257 *argp++ = (char*)"100"; //[8]
257 *argp++ = (char*)"-verify_return_error"; //[9] 258 *argp++ = (char*)"-verify_return_error"; //[9]
258@@ -762,10 +826,10 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 259@@ -762,10 +827,10 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
259 # else 260 # else
260 bb_perror_msg_and_die("can't execute '%s'", argv[0]); 261 bb_perror_msg_and_die("can't execute '%s'", argv[0]);
261 # endif 262 # endif
@@ -268,7 +269,7 @@ index 6a64836fb..831bc4023 100644
268 free(servername); 269 free(servername);
269 free(allocated); 270 free(allocated);
270 close(sp[1]); 271 close(sp[1]);
271@@ -777,6 +841,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port) 272@@ -777,6 +842,7 @@ static int spawn_https_helper_openssl(const char *host, unsigned port)
272 # endif 273 # endif
273 return sp[0]; 274 return sp[0];
274 } 275 }
@@ -276,7 +277,7 @@ index 6a64836fb..831bc4023 100644
276 #endif 277 #endif
277 278
278 #if ENABLE_FEATURE_WGET_HTTPS 279 #if ENABLE_FEATURE_WGET_HTTPS
279@@ -1151,6 +1216,9 @@ static void download_one_url(const char *url) 280@@ -1151,6 +1217,9 @@ static void download_one_url(const char *url)
280 server.user = NULL; 281 server.user = NULL;
281 target.user = NULL; 282 target.user = NULL;
282 283
@@ -286,7 +287,7 @@ index 6a64836fb..831bc4023 100644
286 parse_url(url, &target); 287 parse_url(url, &target);
287 288
288 /* Use the proxy if necessary */ 289 /* Use the proxy if necessary */
289@@ -1234,22 +1302,39 @@ static void download_one_url(const char *url) 290@@ -1234,22 +1303,41 @@ static void download_one_url(const char *url)
290 /* openssl-based helper 291 /* openssl-based helper
291 * Inconvenient API since we can't give it an open fd 292 * Inconvenient API since we can't give it an open fd
292 */ 293 */
@@ -298,7 +299,8 @@ index 6a64836fb..831bc4023 100644
298- spawn_ssl_client(server.host, fileno(sfp), /*flags*/ 0); 299- spawn_ssl_client(server.host, fileno(sfp), /*flags*/ 0);
299- goto socket_opened; 300- goto socket_opened;
300- } 301- }
301+ char *allocated, *servername, *host, *pemmem; 302+ printf("Into section where we config everything\n");
303+ char *allocated, *servername, *host;
302+ if(!strchr(server.host, ':')) 304+ if(!strchr(server.host, ':'))
303+ host = allocated = xasprintf("%s:%u", server.host, server.port); 305+ host = allocated = xasprintf("%s:%u", server.host, server.port);
304+ servername = xstrdup(host); 306+ servername = xstrdup(host);
@@ -329,6 +331,7 @@ index 6a64836fb..831bc4023 100644
329+ //sfp = fdopen(fd, "r+"); 331+ //sfp = fdopen(fd, "r+");
330+ //if (!sfp) 332+ //if (!sfp)
331+ // bb_die_memory_exhausted(); 333+ // bb_die_memory_exhausted();
334+ printf("Got socket!\n");
332 goto socket_opened; 335 goto socket_opened;
333 } 336 }
334- sfp = open_socket(lsa); 337- sfp = open_socket(lsa);
@@ -336,12 +339,13 @@ index 6a64836fb..831bc4023 100644
336 socket_opened: 339 socket_opened:
337 #elif ENABLE_FEATURE_WGET_HTTPS 340 #elif ENABLE_FEATURE_WGET_HTTPS
338 /* Only internal TLS support is configured */ 341 /* Only internal TLS support is configured */
339@@ -1353,7 +1438,39 @@ static void download_one_url(const char *url) 342@@ -1353,7 +1441,41 @@ static void download_one_url(const char *url)
340 shutdown(fileno(sfp), SHUT_WR); 343 shutdown(fileno(sfp), SHUT_WR);
341 } 344 }
342 #endif 345 #endif
343- 346-
344+ //How much data did we actually get? 347+ //How much data did we actually get?
348+ printf("Got to in/out exchange\n");
345+ size_t wlen, bufsize; 349+ size_t wlen, bufsize;
346+ wlen = ftell(sfp); 350+ wlen = ftell(sfp);
347+ if(wlen < 0) 351+ if(wlen < 0)
@@ -374,19 +378,22 @@ index 6a64836fb..831bc4023 100644
374+ bb_error_msg_and_die("tls read error: %s", tls_error(ctx)); 378+ bb_error_msg_and_die("tls read error: %s", tls_error(ctx));
375+ rewind(dfp); 379+ rewind(dfp);
376+ sfp = dfp; 380+ sfp = dfp;
381+ printf("finished in/out exchange\n");
377 /* 382 /*
378 * Retrieve HTTP response line and check for "200" status code. 383 * Retrieve HTTP response line and check for "200" status code.
379 */ 384 */
380@@ -1536,6 +1653,8 @@ However, in real world it was observed that some web servers 385@@ -1536,6 +1658,10 @@ However, in real world it was observed that some web servers
381 /* ftpcmd("QUIT", NULL, sfp); - why bother? */ 386 /* ftpcmd("QUIT", NULL, sfp); - why bother? */
382 } 387 }
383 #endif 388 #endif
389+ printf("About to clean up connection\n");
384+ if(ctx != NULL) 390+ if(ctx != NULL)
385+ tls_close(ctx); 391+ tls_close(ctx);
392+ printf("Cleaned up connection\n");
386 fclose(sfp); 393 fclose(sfp);
387 394
388 free(server.allocated); 395 free(server.allocated);
389@@ -1690,10 +1809,18 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") 396@@ -1690,9 +1816,18 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
390 xdup2(G.log_fd, STDERR_FILENO); 397 xdup2(G.log_fd, STDERR_FILENO);
391 } 398 }
392 } 399 }
@@ -399,14 +406,14 @@ index 6a64836fb..831bc4023 100644
399+ printf("Got to downloading section\n"); 406+ printf("Got to downloading section\n");
400 while (*argv) 407 while (*argv)
401 download_one_url(*argv++); 408 download_one_url(*argv++);
402 409+ printf("Finished downloading section\n");
403+ free(pemmem); 410+ free(pemmem);
404+ tls_config_free(G.tlscfg); 411+ tls_config_free(G.tlscfg);
405+ 412+ printf("Freed everythign\n");
413
406 if (G.output_fd >= 0) 414 if (G.output_fd >= 0)
407 xclose(G.output_fd); 415 xclose(G.output_fd);
408 416@@ -1704,6 +1839,6 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
409@@ -1704,6 +1831,6 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
410 free(G.extra_headers); 417 free(G.extra_headers);
411 #endif 418 #endif
412 FINI_G(); 419 FINI_G();