crond: do not assume setenv() does not leak

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-07-22 02:25:47 +02:00
parent ef0366eb4f
commit bbf17bbf32
2 changed files with 21 additions and 3 deletions

View File

@ -79,9 +79,9 @@
#include "common_bufsiz.h" #include "common_bufsiz.h"
#include <syslog.h> #include <syslog.h>
/* glibc frees previous setenv'ed value when we do next setenv() #if 0
* of the same variable. uclibc does not do this! */ /* If libc tracks and reuses setenv()-allocated memory, ok to set this to 0 */
#if (defined(__GLIBC__) && !defined(__UCLIBC__)) /* || OTHER_SAFE_LIBC... */ /* Neither glibc nor uclibc do that! */
# define SETENV_LEAKS 0 # define SETENV_LEAKS 0
#else #else
# define SETENV_LEAKS 1 # define SETENV_LEAKS 1

View File

@ -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;
}