aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-07-22 02:25:47 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-07-22 02:25:47 +0200
commitbbf17bbf326c7157ca237b9659472ddf7626e68d (patch)
tree95450d50a1931a6b13f941cdf3deb036506148df
parentef0366eb4f02bb0cda359b977fdbdfa7c145f76f (diff)
downloadbusybox-w32-bbf17bbf326c7157ca237b9659472ddf7626e68d.tar.gz
busybox-w32-bbf17bbf326c7157ca237b9659472ddf7626e68d.tar.bz2
busybox-w32-bbf17bbf326c7157ca237b9659472ddf7626e68d.zip
crond: do not assume setenv() does not leak
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/crond.c6
-rw-r--r--scripts/test_setenv_leak.c18
2 files changed, 21 insertions, 3 deletions
diff --git a/miscutils/crond.c b/miscutils/crond.c
index cf3323090..5ae0ff084 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -79,9 +79,9 @@
79#include "common_bufsiz.h" 79#include "common_bufsiz.h"
80#include <syslog.h> 80#include <syslog.h>
81 81
82/* glibc frees previous setenv'ed value when we do next setenv() 82#if 0
83 * of the same variable. uclibc does not do this! */ 83/* If libc tracks and reuses setenv()-allocated memory, ok to set this to 0 */
84#if (defined(__GLIBC__) && !defined(__UCLIBC__)) /* || OTHER_SAFE_LIBC... */ 84/* Neither glibc nor uclibc do that! */
85# define SETENV_LEAKS 0 85# define SETENV_LEAKS 0
86#else 86#else
87# define SETENV_LEAKS 1 87# define SETENV_LEAKS 1
diff --git a/scripts/test_setenv_leak.c b/scripts/test_setenv_leak.c
new file mode 100644
index 000000000..e51722ca7
--- /dev/null
+++ b/scripts/test_setenv_leak.c
@@ -0,0 +1,18 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4int main(int argc, char **argv)
5{
6 char buf[256];
7
8 int i = argv[1] ? atoi(argv[1]) : 999999;
9 while (--i > 0) {
10 sprintf(buf, "%d", i);
11 setenv("VAR", buf, 1);
12 }
13 printf("Check size of [heap] mapping:\n");
14 freopen("/proc/self/maps", "r", stdin);
15 while (fgets(buf, sizeof(buf), stdin))
16 fputs(buf, stdout);
17 return 0;
18}