crond: do not assume setenv() does not leak
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 22 Jul 2017 00:25:47 +0000 (02:25 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 22 Jul 2017 00:25:47 +0000 (02:25 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/crond.c
scripts/test_setenv_leak.c [new file with mode: 0644]

index cf33230905999f54e0e941d6e3d1bb2bd0c309a1..5ae0ff084ef246461085c60f976345013878fe39 100644 (file)
@@ -79,9 +79,9 @@
 #include "common_bufsiz.h"
 #include <syslog.h>
 
-/* glibc frees previous setenv'ed value when we do next setenv()
- * of the same variable. uclibc does not do this! */
-#if (defined(__GLIBC__) && !defined(__UCLIBC__)) /* || OTHER_SAFE_LIBC... */
+#if 0
+/* If libc tracks and reuses setenv()-allocated memory, ok to set this to 0 */
+/* Neither glibc nor uclibc do that! */
 # define SETENV_LEAKS 0
 #else
 # define SETENV_LEAKS 1
diff --git a/scripts/test_setenv_leak.c b/scripts/test_setenv_leak.c
new file mode 100644 (file)
index 0000000..e51722c
--- /dev/null
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+int main(int argc, char **argv)
+{
+       char buf[256];
+
+       int i = argv[1] ? atoi(argv[1]) : 999999;
+       while (--i > 0) {
+               sprintf(buf, "%d", i);
+               setenv("VAR", buf, 1);
+       }
+       printf("Check size of [heap] mapping:\n");
+       freopen("/proc/self/maps", "r", stdin);
+       while (fgets(buf, sizeof(buf), stdin))
+               fputs(buf, stdout);
+       return 0;
+}