Skip to content

Commit

Permalink
coverity: #1427668
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 7, 2018
1 parent e14d827 commit a48622d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/lxc/lxc_init.c
Expand Up @@ -76,23 +76,25 @@ static void usage(void) {

static void remove_self(void)
{
char path[PATH_MAX];
int ret;
ssize_t n;
char path[MAXPATHLEN] = {0};

n = readlink("/proc/self/exe", path, sizeof(path));
if (n < 0) {
if (n < 0 || n >= MAXPATHLEN) {
SYSERROR("Failed to readlink \"/proc/self/exe\"");
return;
}
path[n] = '\0';

path[n] = 0;

if (umount2(path, MNT_DETACH) < 0) {
ret = umount2(path, MNT_DETACH);
if (ret < 0) {
SYSERROR("Failed to unmount \"%s\"", path);
return;
}

if (unlink(path) < 0) {
ret = unlink(path);
if (ret < 0) {
SYSERROR("Failed to unlink \"%s\"", path);
return;
}
Expand Down

0 comments on commit a48622d

Please sign in to comment.