summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2016-09-12 18:32:54 +0000
committermillert <millert@openbsd.org>2016-09-12 18:32:54 +0000
commitfc5b63731377e9c428d5d9f0d567937caa818ddc (patch)
tree8d77b3e393f329e94f2d9eaf44a897180c0355e6
parentAdd support for packets spanning multiple pages. (diff)
downloadwireguard-openbsd-fc5b63731377e9c428d5d9f0d567937caa818ddc.tar.xz
wireguard-openbsd-fc5b63731377e9c428d5d9f0d567937caa818ddc.zip
If we can't get the CWD, use relative paths. Fixes editing files
in a directory without read permission. OK lum@
-rw-r--r--usr.bin/mg/dir.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/usr.bin/mg/dir.c b/usr.bin/mg/dir.c
index 5960b909f3d..bcbab5c12f7 100644
--- a/usr.bin/mg/dir.c
+++ b/usr.bin/mg/dir.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dir.c,v 1.28 2015/03/19 21:22:15 bcallah Exp $ */
+/* $OpenBSD: dir.c,v 1.29 2016/09/12 18:32:54 millert Exp $ */
/* This file is in the public domain. */
@@ -27,11 +27,9 @@ void
dirinit(void)
{
mgcwd[0] = '\0';
- if (getcwd(mgcwd, sizeof(mgcwd)) == NULL) {
+ if (getcwd(mgcwd, sizeof(mgcwd)) == NULL)
ewprintf("Can't get current directory!");
- chdir("/");
- }
- if (!(mgcwd[0] == '/' && mgcwd [1] == '\0'))
+ if (mgcwd[0] != '\0' && !(mgcwd[0] == '/' && mgcwd[1] == '\0'))
(void)strlcat(mgcwd, "/", sizeof(mgcwd));
}
@@ -56,11 +54,15 @@ changedir(int f, int n)
ewprintf("Can't change dir to %s", bufc);
return (FALSE);
}
- if ((bufp = getcwd(mgcwd, sizeof(mgcwd))) == NULL)
- panic("Can't get current directory!");
+ if ((bufp = getcwd(mgcwd, sizeof(mgcwd))) == NULL) {
+ if (bufc[0] == '/')
+ (void)strlcpy(mgcwd, bufc, sizeof(mgcwd));
+ else
+ (void)strlcat(mgcwd, bufc, sizeof(mgcwd));
+ }
if (mgcwd[strlen(mgcwd) - 1] != '/')
(void)strlcat(mgcwd, "/", sizeof(mgcwd));
- ewprintf("Current directory is now %s", bufp);
+ ewprintf("Current directory is now %s", mgcwd);
return (TRUE);
}