chiark / gitweb /
core: add extra safety check before switching root
authorLennart Poettering <lennart@poettering.net>
Fri, 11 May 2012 15:17:57 +0000 (17:17 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 14 May 2012 20:41:30 +0000 (22:41 +0200)
src/core/dbus-manager.c

index 6ad198436ad89af5b9074eafd8d595728ab2e0f4..33dcb56c09af48a36a63d498310afd962906ca14 100644 (file)
@@ -1186,6 +1186,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SwitchRoot")) {
                 const char *switch_root, *switch_root_init;
                 char *u, *v;
         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SwitchRoot")) {
                 const char *switch_root, *switch_root_init;
                 char *u, *v;
+                int k;
 
                 if (!dbus_message_get_args(
                                     message,
 
                 if (!dbus_message_get_args(
                                     message,
@@ -1206,6 +1207,22 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                         return bus_send_error_reply(connection, message, &error, -ENOTSUP);
                 }
 
                         return bus_send_error_reply(connection, message, &error, -ENOTSUP);
                 }
 
+                /* Safety check */
+                if (isempty(switch_root_init))
+                        k = access(switch_root, F_OK);
+                else {
+                        char *p;
+
+                        p = join(switch_root, "/", switch_root_init, NULL);
+                        if (!p)
+                                goto oom;
+
+                        k = access(p, X_OK);
+                        free(p);
+                }
+                if (k < 0)
+                        return bus_send_error_reply(connection, message, NULL, -errno);
+
                 u = strdup(switch_root);
                 if (!u)
                         goto oom;
                 u = strdup(switch_root);
                 if (!u)
                         goto oom;