diff --git a/namespaces/nsenter/nsenter.c b/namespaces/nsenter/nsenter.c index b735b1fa..09a0b9b2 100644 --- a/namespaces/nsenter/nsenter.c +++ b/namespaces/nsenter/nsenter.c @@ -22,6 +22,11 @@ void get_args(int *argc, char ***argv) { // Read argv int fd = open("/proc/self/cmdline", O_RDONLY); + if (fd < 0) { + fprintf(stderr, + "nsenter: Unable to open /proc/self/cmdline: %m\n"); + exit(1); + } // Read the whole commandline. ssize_t contents_size = 0; @@ -34,6 +39,11 @@ void get_args(int *argc, char ***argv) bytes_read = read(fd, contents + contents_offset, contents_size - contents_offset); + if (bytes_read < 0) { + fprintf(stderr, + "nsenter: Unable to read from /proc/self/cmdline: %m\n"); + exit(1); + } contents_offset += bytes_read; } while (bytes_read > 0); @@ -184,6 +194,10 @@ void nsenter() // We must fork to actually enter the PID namespace. int child = fork(); + if (child == -1) { + fprintf(stderr, "nsenter: Unable to fork a process: %m\n"); + exit(1); + } if (child == 0) { if (consolefd != -1) { if (dup2(consolefd, STDIN_FILENO) != 0) {