From 4e0968182c7a23404d0f480c32f5c90865177163 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 14 Mar 2016 17:09:11 +0100 Subject: [PATCH] nmp-netns: fix error handling GError is not used, the error branch would always result in NULL dereference. Also, check for the result being zero for clarity -- it's the only allowed success indication. CID 75365 (#3 of 3): Explicit null dereferenced (FORWARD_NULL) 12. var_deref_op: Dereferencing null pointer error. --- src/platform/nmp-netns.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/platform/nmp-netns.c b/src/platform/nmp-netns.c index d7c32b929..47a8f1797 100644 --- a/src/platform/nmp-netns.c +++ b/src/platform/nmp-netns.c @@ -318,18 +318,21 @@ nmp_netns_new (void) return NULL; } - if (mount ("", "/", "none", MS_SLAVE | MS_REC, NULL)) { - _LOGE (NULL, "failed mount --make-rslave: %s", error->message); + if (mount ("", "/", "none", MS_SLAVE | MS_REC, NULL) != 0) { + errsv = errno; + _LOGE (NULL, "failed mount --make-rslave: %s", g_strerror (errsv)); goto err_out; } - if (umount2 ("/sys", MNT_DETACH) < 0) { - _LOGE (NULL, "failed umount /sys: %s", error->message); + if (umount2 ("/sys", MNT_DETACH) != 0) { + errsv = errno; + _LOGE (NULL, "failed umount /sys: %s", g_strerror (errsv)); goto err_out; } - if (mount ("sysfs", "/sys", "sysfs", 0, NULL) < 0) { - _LOGE (NULL, "failed mount /sys: %s", error->message); + if (mount ("sysfs", "/sys", "sysfs", 0, NULL) != 0) { + errsv = errno; + _LOGE (NULL, "failed mount /sys: %s", g_strerror (errsv)); goto err_out; }