diff options
author | Julian Andres Klode <jak@debian.org> | 2015-12-14 13:12:37 +0100 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2015-12-14 13:14:22 +0100 |
commit | d27daedb6a0bf672508072100f20233d08ccf0e0 (patch) | |
tree | 59c3a454e138d7cab63abaa055bed0811b5153b7 | |
parent | c95c96746d93a6f2d94ee96f8abf3e324bfb690a (diff) |
test framework: Correctly generate new paths in noopchroot
The allocated buffer was one byte too small. Allocate a buffer
of PATH_MAX instead and use snprintf(), as suggested by Martin
Pitt.
-rw-r--r-- | test/integration/framework | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/test/integration/framework b/test/integration/framework index 691eb793b..8ea1e1c0d 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -477,6 +477,7 @@ configdpkgnoopchroot() { #include <stdlib.h> #include <string.h> #include <dlfcn.h> +#include <limits.h> static char * chrootdir = NULL; @@ -493,13 +494,11 @@ int execvp(const char *file, char *const argv[]) { if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0) return func_execvp(file, argv); printf("REWRITE execvp call %s into %s\n", file, chrootdir); - char newfile[strlen(chrootdir) + strlen(file)]; - strcpy(newfile, chrootdir); - strcat(newfile, file); + char newfile[PATH_MAX]; + snprintf(newfile, sizeof(newfile), "%s/%s", chrootdir, file); char const * const baseadmindir = "/var/lib/dpkg"; - char admindir[strlen(chrootdir) + strlen(baseadmindir)]; - strcpy(admindir, chrootdir); - strcat(admindir, baseadmindir); + char admindir[PATH_MAX]; + snprintf(admindir, sizeof(admindir), "%s/%s", chrootdir, baseadmindir); setenv("DPKG_ADMINDIR", admindir, 1); return func_execvp(newfile, argv); } |