aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2015-09-12 13:50:28 -0400
committerAustin Adams <git@austinjadams.com>2015-09-12 13:50:28 -0400
commitde522bea76293ac3ad149ef2e0dd6a70fbaa2e04 (patch)
treeb345b010e12e8f65ff99f540cb8a0403e885ffed
parent3439fce5f745bd0ea4fe41747afe8c6010e108c6 (diff)
downloadnsdo-de522bea76293ac3ad149ef2e0dd6a70fbaa2e04.tar.gz
nsdo-de522bea76293ac3ad149ef2e0dd6a70fbaa2e04.tar.xz
improve handling of invalid namespace names
1. don't accept empty namespace names. running setns(open("/run/netns")) as root is probably harmless, but I'd like to avoid it. 2. if a namespace can't be open()ed, give the filename nsdo tried to open. Then, maybe the user can try to find the file by hand.
-rw-r--r--nsdo.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/nsdo.c b/nsdo.c
index 7fed018..c762b0c 100644
--- a/nsdo.c
+++ b/nsdo.c
@@ -135,7 +135,7 @@ int already_in_namespace() {
}
int bad_nsname(char *ns) {
- return strcmp("..", ns) == 0 || strcmp(".", ns) == 0 || strchr(ns, '/') != NULL;
+ return strlen(ns) == 0 || strcmp("..", ns) == 0 || strcmp(".", ns) == 0 || strchr(ns, '/') != NULL;
}
int set_netns(char *ns) {
@@ -143,7 +143,7 @@ int set_netns(char *ns) {
char *nspath;
if (bad_nsname(ns)) {
- fprintf(stderr, PROGRAM ": namespace names may not contain '/' or be '.', '..'\n");
+ fprintf(stderr, PROGRAM ": namespace names can't contain '/', be empty, or be '.' or '..'.\n");
return 0;
}
@@ -153,7 +153,7 @@ int set_netns(char *ns) {
}
if ((nsfd = open(nspath, O_RDONLY)) == -1) {
- perror(PROGRAM ": open");
+ fprintf(stderr, PROGRAM ": open(\"%s\"): %s\n", nspath, strerror(errno));
return 0;
}