]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
seccomp: parse_v2_rules()
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 24 May 2018 14:22:58 +0000 (16:22 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 24 May 2018 15:45:56 +0000 (17:45 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/seccomp.c

index 176964c3a743f917b7a2878264a6fbdbeed06332..33994d489b0d387bde88e837735317873239ea34 100644 (file)
@@ -235,13 +235,11 @@ static int get_seccomp_arg_value(char *key, struct seccomp_v2_rule_args *rule_ar
  * @rules      : output struct.
  * Returns 0 on success, < 0 otherwise.
  */
-static int parse_v2_rules(char *line, uint32_t def_action, struct seccomp_v2_rule *rules)
+static int parse_v2_rules(char *line, uint32_t def_action,
+                         struct seccomp_v2_rule *rules)
 {
-       int ret = 0 ;
-       int i = 0;
-       char *tmp = NULL;
-       char *key = NULL;
-       char *saveptr = NULL;
+       int i = 0, ret = -1;
+       char *key = NULL, *saveptr = NULL, *tmp = NULL;
 
        tmp = strdup(line);
        if (!tmp)
@@ -249,33 +247,29 @@ static int parse_v2_rules(char *line, uint32_t def_action, struct seccomp_v2_rul
 
        /* read optional action which follows the syscall */
        rules->action = get_v2_action(tmp, def_action);
-       if (rules->action == -1) {
-               ERROR("Failed to interpret action");
-               ret = -1;
-               goto out;
-       }
 
+       ret = 0;
        rules->args_num = 0;
-       if (!strchr(tmp, '[')) {
-               ret = 0;
+       if (!strchr(tmp, '['))
                goto out;
-       }
 
-       for ((key = strtok_r(tmp, "]", &saveptr)), i = 0; key && i < 6; (key = strtok_r(NULL, "]", &saveptr)), i++) {
+       ret = -1;
+       for ((key = strtok_r(tmp, "]", &saveptr)), i = 0; key && i < 6;
+            (key = strtok_r(NULL, "]", &saveptr)), i++) {
                ret = get_seccomp_arg_value(key, &rules->args_value[i]);
-               if (ret < 0) {
-                       ret = -1;
+               if (ret < 0)
                        goto out;
-               }
+
                rules->args_num++;
        }
 
        ret = 0;
+
 out:
        free(tmp);
+
        return ret;
 }
-
 #endif
 
 #if HAVE_DECL_SECCOMP_SYSCALL_RESOLVE_NAME_ARCH