Commit f4282b47 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

zdtm/cwd01: avoid resolving an abs path

We may not have permissions for this.

Reported-by: Mr Jenkins
Fixes: 7dbd38db ("zdtm: set additional groups along with uids and gids")
Cc: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Acked-by: 's avatarRuslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 18d40fdd
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#include <string.h> #include <string.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <linux/limits.h> #include <linux/limits.h>
#include <sys/types.h>
#include <fcntl.h>
#include "zdtmtst.h" #include "zdtmtst.h"
...@@ -16,8 +19,8 @@ TEST_OPTION(dirname, string, "directory name", 1); ...@@ -16,8 +19,8 @@ TEST_OPTION(dirname, string, "directory name", 1);
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char cwd0[PATH_MAX], cwd1[PATH_MAX], cwd2[PATH_MAX]; char cwd1[PATH_MAX], cwd2[PATH_MAX];
int pid, p[2], aux, aux2; int pid, p[2], aux, aux2, fd;
test_init(argc, argv); test_init(argc, argv);
...@@ -30,8 +33,9 @@ int main(int argc, char **argv) ...@@ -30,8 +33,9 @@ int main(int argc, char **argv)
exit(aux ? 1 : 0); exit(aux ? 1 : 0);
} }
if (!getcwd(cwd0, sizeof(cwd0))) { fd = open(".", O_DIRECTORY | O_RDONLY);
err("can't get cwd: %m\n"); if (fd == -1) {
err("Unable to open the current dir");
exit(1); exit(1);
} }
...@@ -87,8 +91,8 @@ int main(int argc, char **argv) ...@@ -87,8 +91,8 @@ int main(int argc, char **argv)
pass(); pass();
cleanup: cleanup:
/* return to the initial dir before writing out results */ /* return to the initial dir before writing out results */
if (chdir(cwd0)) { if (fchdir(fd)) {
err("can't change directory to %s: %m\n", cwd0); err("can't restore cwd");
exit(1); exit(1);
} }
......
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