]> git.proxmox.com Git - mirror_libseccomp.git/commitdiff
tests: correctly return an error if seccomp_init() fails
authorPaul Moore <pmoore@redhat.com>
Wed, 23 Apr 2014 22:34:49 +0000 (18:34 -0400)
committerPaul Moore <pmoore@redhat.com>
Thu, 1 May 2014 18:15:49 +0000 (14:15 -0400)
Signed-off-by: Paul Moore <pmoore@redhat.com>
26 files changed:
tests/01-sim-allow.c
tests/02-sim-basic.c
tests/03-sim-basic_chains.c
tests/04-sim-multilevel_chains.c
tests/05-sim-long_jumps.c
tests/06-sim-actions.c
tests/07-sim-db_bug_looping.c
tests/08-sim-subtree_checks.c
tests/09-sim-syscall_priority_pre.c
tests/10-sim-syscall_priority_post.c
tests/11-basic-basic_errors.c
tests/12-sim-basic_masked_ops.c
tests/13-basic-attrs.c
tests/14-sim-reset.c
tests/15-basic-resolver.c
tests/16-sim-arch_basic.c
tests/17-sim-arch_merge.c
tests/18-sim-basic_whitelist.c
tests/19-sim-missing_syscalls.c
tests/20-live-basic_die.c
tests/21-live-basic_allow.c
tests/22-sim-basic_chains_array.c
tests/23-sim-arch_all_le_basic.c
tests/24-live-arg_allow.c
tests/25-sim-multilevel_chains_adv.c
tests/26-sim-arch_all_be_basic.c

index 947e9d9172125df5b32a45ecfbeeeef4bda80a23..6de906d6c0d26991b2fb8e081fd7ef3ab836da80 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_ALLOW);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = util_filter_output(&opts, ctx);
        if (rc)
index f902a47b9001633a26a0ed378c845852562d50e9..c3431566cba76d6705262afc6bf5dab227c2f560 100644 (file)
@@ -24,6 +24,7 @@
  * read, write, exit, and rt_sigreturn
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -42,8 +43,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
-
+               return ENOMEM;
 
        rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0);
        if (rc != 0)
index 06a0d15333e1d84150a35ae70d1b497699a3685c..011e3b3e0e4649436c0e9e6afe1b43610c97ace8 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 1,
                                    SCMP_A0(SCMP_CMP_EQ, STDIN_FILENO));
index c504d227c96bd08bc99fbfa4872bbafb378109a3..83bbfd5fe291382ada200e03159e8814ea65f69e 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <limits.h>
 #include <unistd.h>
 
@@ -38,7 +39,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open), 0);
        if (rc != 0)
index 0046e076c241ea0d262e034807c43cbcf2231f59..d48398c75d36d1e34c2be1bda1b5ddae127f566a 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 #include <limits.h>
 
@@ -39,7 +40,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        /* NOTE - syscalls referenced by number to make the test simpler */
 
index 68b037c1ddb30e6372c73092c8eeb3b1f1f2adc2..4dbe19f8448457568a1bca0f40ebb563afad50eb 100644 (file)
@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0);
        if (rc != 0)
index 68afbe12414645a1c6ea12fa2790c0e366d201ff..e3fec813a8fc8e17aed4c8e45f9b7d0b01c42142 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        /* The next three seccomp_rule_add_exact() calls for read must
         * go together in this order to catch an infinite loop. */
index 42fce309a7b3a11ddcd9c3046d1402550f427ae7..e187ceeb7f342b83958e8086f5432a3bfb9ebb96 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        /* the syscall and argument numbers are all fake to make the test
         * simpler */
index c820ac86036ea5436b364942c4a84c6a03dfb346..68e35a5591a063257392509a089cd5f53337c0f1 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        /* the syscall and argument numbers are all fake to make the test
         * simpler */
index d426e14eb14d897236044c98741d2e60ab577164..1e8712d8141ca78adb57a96426fc83df1bf55f81 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        /* the syscall and argument numbers are all fake to make the test
         * simpler */
index 4ebd43ad88f0fbcb7247b98bce288ed4592ff3d5..2b7220572b2e1c977d1537042558affe6a038266 100644 (file)
@@ -19,8 +19,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
-#include <unistd.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include <seccomp.h>
 
index 29b86d62f1941e36aff85118bb20002cd75567b4..5c699f3fce35560560c3a9a51322daf2bfecbb91 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        /* the syscall and argument numbers are all fake to make the test
         * simpler */
index 091c8ed83fa96d7cbdf8e1dd9c764218c82390ae..2cd8d29b358e632960f39e6897ed1f4446add654 100644 (file)
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_ALLOW);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_attr_get(ctx, SCMP_FLTATR_ACT_DEFAULT, &val);
        if (rc != 0)
index c87ba13832e1f2eb610395beb7e60c463d6e0f31..039974f0f9d36fe260e245a2c11d5c825d65d757 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,8 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
-
+               return ENOMEM;
 
        rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0);
        if (rc != 0)
index a103a1ab0d1590cd42e32a2330afcc43cd329da8..a8988fd6587013fe11e3c6835aef17aeaafd3263 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <string.h>
 
 #include <seccomp.h>
index d63a1c4644f70aafba879d8013282df0282ad11d..8e54c0aa53337d5f8f9198066d8726678ac8cd03 100644 (file)
@@ -19,8 +19,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
-#include <unistd.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include <seccomp.h>
 
@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE);
        if (rc != 0)
index cb0e33c2faedba3fc706763da1dc2a10ef1be135..58af194cc8768b921917bd42908ce6b73c5ad962 100644 (file)
@@ -19,8 +19,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
-#include <unistd.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include <seccomp.h>
 
@@ -37,11 +37,15 @@ int main(int argc, char *argv[])
                goto out_all;
 
        ctx_32 = seccomp_init(SCMP_ACT_KILL);
-       if (ctx_32 == NULL)
+       if (ctx_32 == NULL) {
+               rc = -ENOMEM;
                goto out_all;
+       }
        ctx_64 = seccomp_init(SCMP_ACT_KILL);
-       if (ctx_64 == NULL)
+       if (ctx_64 == NULL) {
+               rc = -ENOMEM;
                goto out_all;
+       }
 
        rc = seccomp_arch_remove(ctx_32, SCMP_ARCH_NATIVE);
        if (rc != 0)
index d312f18e3724b93bf4065452a3091e5e873c52bc..d07a3b6852f6b55192df1cc239da5aab1c8cb543 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_ALLOW);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_rule_add_exact(ctx, SCMP_ACT_KILL, SCMP_SYS(read), 1,
                                    SCMP_A0(SCMP_CMP_EQ, STDIN_FILENO));
index fec9185994e5901d261b94739fcb512e8d234354..50862dcc8a0fc8be6a083272ba99d8000c5aadf5 100644 (file)
@@ -38,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE);
        if (rc != 0)
index 1dda6d705e40f89cc323d3901b8601f220a9ee23..5e6a99b9b855917335a9582b3d4a2a84d45435d3 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -44,7 +45,8 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(action);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
+
        rc = seccomp_rule_add_exact(ctx,
                                    SCMP_ACT_ALLOW, SCMP_SYS(rt_sigreturn), 0);
        if (rc != 0)
@@ -53,6 +55,7 @@ int main(int argc, char *argv[])
                                    SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0);
        if (rc != 0)
                goto out;
+
        rc = seccomp_load(ctx);
        if (rc != 0)
                goto out;
index dccc6567022dc67eb611219e57e82255c99260c1..690f98eb3cb44286b84e480f321491fe9966bccc 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -42,7 +43,8 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_TRAP);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
+
        rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open), 0);
        if (rc != 0)
                goto out;
@@ -60,6 +62,7 @@ int main(int argc, char *argv[])
                                    SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0);
        if (rc != 0)
                goto out;
+
        rc = seccomp_load(ctx);
        if (rc != 0)
                goto out;
index e3c961376e80593e44cb080738d7221be69e69bb..f1be656f65a0f1ed830a04790ead765b912398f0 100644 (file)
@@ -18,6 +18,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        arg_cmp = SCMP_A0(SCMP_CMP_EQ, STDIN_FILENO);
        rc = seccomp_rule_add_exact_array(ctx, SCMP_ACT_ALLOW,
index 92f5eb752c1561609c93abe7c1624e229efbecb0..446a8d88e73512ec2c55f22a8d9dbaa3ef9ef5f2 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE);
        if (rc != 0)
index 7c50c96bb4e792ad08cf95cc07e473928b21b793..2ee8377cef6681d4c2d2e30c379fd4819373be90 100644 (file)
@@ -56,7 +56,8 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_TRAP);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
+
        rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1,
                                    SCMP_A0(SCMP_CMP_EQ, fd));
        if (rc != 0)
@@ -72,6 +73,7 @@ int main(int argc, char *argv[])
                                    SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0);
        if (rc != 0)
                goto out;
+
        rc = seccomp_load(ctx);
        if (rc != 0)
                goto out;
index 0ef7f678f3ab97886760c44b7de9a1ccf09db2ae..a284aa4d7e8b386842bc6bd8725265cc13c5ae0e 100644 (file)
@@ -19,6 +19,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <stdlib.h>
 
 #include <seccomp.h>
@@ -37,7 +38,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 10, 2,
                                    SCMP_A0(SCMP_CMP_EQ, 11),
index 253138b756623d927ad3f902cdbebef2fed23275..be892fbd10a98cd7628944c13e77ed8340a99ebe 100644 (file)
@@ -18,6 +18,7 @@
  * along with this library; if not, see <http://www.gnu.org/licenses>.
  */
 
+#include <errno.h>
 #include <unistd.h>
 
 #include <seccomp.h>
@@ -36,7 +37,7 @@ int main(int argc, char *argv[])
 
        ctx = seccomp_init(SCMP_ACT_KILL);
        if (ctx == NULL)
-               goto out;
+               return ENOMEM;
 
        rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE);
        if (rc != 0)