# # patch for CR 21326204 (ProFTPD dumps core with long env variable) # fix has been sent to upstream master branch: # https://github.com/proftpd/proftpd/pull/702 # # Unfortunately pull request above causes a regression, which is # addressed by yet another pull request: # https://github.com/proftpd/proftpd/issues/742 # # Patch below merges both changes to single patch. We can remove # the patch on upgrade to 1.3.7 # diff --git a/src/proctitle.c b/src/proctitle.c index ec41aaf55..69496409f 100644 --- a/src/proctitle.c +++ b/src/proctitle.c @@ -60,7 +60,7 @@ static unsigned int proc_flags = 0; #define PR_PROCTITLE_FL_USE_STATIC 0x001 void pr_proctitle_init(int argc, char *argv[], char *envp[]) { - register int i; + register int i, j; register size_t envpsize; char **p; @@ -69,10 +69,11 @@ void pr_proctitle_init(int argc, char *argv[], char *envp[]) { envpsize += strlen(envp[i]) + 1; } - p = (char **) malloc((i + 1) * sizeof(char *)); + p = (char **) calloc((i + 1), sizeof(char *)); if (p != NULL) { environ = p; + j = 0; for (i = 0; envp[i] != NULL; i++) { size_t envp_len = strlen(envp[i]); @@ -81,13 +82,13 @@ void pr_proctitle_init(int argc, char *argv[], char *envp[]) { continue; } - environ[i] = malloc(envp_len + 1); - if (environ[i] != NULL) { - sstrncpy(environ[i], envp[i], envp_len + 1); + environ[j] = malloc(envp_len + 1); + if (environ[j] != NULL) { + sstrncpy(environ[j], envp[i], envp_len + 1); + j++; } } - environ[i] = NULL; } prog_argv = argv;