nmp-netns: fix error handling
authorLubomir Rintel <lkundrak@v3.sk>
Mon, 14 Mar 2016 16:09:11 +0000 (17:09 +0100)
committerLubomir Rintel <lkundrak@v3.sk>
Tue, 15 Mar 2016 08:00:03 +0000 (09:00 +0100)
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

index d7c32b9..47a8f17 100644 (file)
@@ -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;
        }