Commit c7390d2d authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm/cwd01: don't forget to set '\0' after readlink()

Reported-by: 's avatarKonstantin Neumoin <kneumoin@parallels.com>
Cc: Konstantin Neumoin <kneumoin@parallels.com>
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8ac80915
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <linux/limits.h>
#include "zdtmtst.h" #include "zdtmtst.h"
...@@ -15,8 +16,8 @@ TEST_OPTION(dirname, string, "directory name", 1); ...@@ -15,8 +16,8 @@ TEST_OPTION(dirname, string, "directory name", 1);
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char cwd0[256], cwd1[256], cwd2[256]; char cwd0[PATH_MAX], cwd1[PATH_MAX], cwd2[PATH_MAX];
int pid, p[2], aux; int pid, p[2], aux, aux2;
test_init(argc, argv); test_init(argc, argv);
...@@ -57,16 +58,27 @@ int main(int argc, char **argv) ...@@ -57,16 +58,27 @@ int main(int argc, char **argv)
err("can't get cwd: %m\n"); err("can't get cwd: %m\n");
goto cleanup; goto cleanup;
} }
if (aux == sizeof(cwd1)) {
err("A buffer is too small");
goto cleanup;
}
cwd1[aux] = '\0'; cwd1[aux] = '\0';
test_daemon(); test_daemon();
test_waitsig(); test_waitsig();
if (readlink("/proc/self/cwd", cwd2, sizeof(cwd2)) < 0) { aux2 = readlink("/proc/self/cwd", cwd2, sizeof(cwd2));
if (aux2 < 0) {
fail("can't get cwd: %m\n"); fail("can't get cwd: %m\n");
goto cleanup; goto cleanup;
} }
if (aux2 == sizeof(cwd2)) {
err("A buffer is too small");
goto cleanup;
}
cwd2[aux2] = '\0';
/* FIXME -- criu adds a suffix to removed cwd */ /* FIXME -- criu adds a suffix to removed cwd */
if (strncmp(cwd1, cwd2, aux)) if (strncmp(cwd1, cwd2, aux))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment