From 2fd795b61caca9ddd0179f409cd1fe12e5dfc541 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Wed, 24 Dec 2014 22:32:00 +0300 Subject: [PATCH] zdtm/cwd02: avoid resolving an abs path We may not have permissions for this. Reported-by: Mr Jenkins Fixes: 7dbd38dbc939 ("zdtm: set additional groups along with uids and gids") Cc: Ruslan Kuprieiev Signed-off-by: Andrew Vagin Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- test/zdtm/live/static/cwd02.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/zdtm/live/static/cwd02.c b/test/zdtm/live/static/cwd02.c index e7747f4f4..173ddb4a7 100644 --- a/test/zdtm/live/static/cwd02.c +++ b/test/zdtm/live/static/cwd02.c @@ -16,8 +16,7 @@ TEST_OPTION(dirname, string, "directory name", 1); int main(int argc, char **argv) { - char cwd0[256]; - int fd, pid, p[2], aux; + int cwd, fd, pid, p[2], aux; struct stat std, stf; test_init(argc, argv); @@ -31,8 +30,9 @@ int main(int argc, char **argv) exit(aux ? 1 : 0); } - if (!getcwd(cwd0, sizeof(cwd0))) { - err("can't get cwd: %m\n"); + cwd = open(".", O_DIRECTORY | O_RDONLY); + if (cwd == -1) { + err("Unable to open the current dir"); exit(1); } @@ -82,8 +82,8 @@ int main(int argc, char **argv) cleanup: /* return to the initial dir before writing out results */ - if (chdir(cwd0)) { - err("can't change directory to %s: %m\n", cwd0); + if (fchdir(cwd)) { + err("can't restore cwd"); exit(1); }