From 5f95a0d49aa29c2a07e38a9b2b476bb106a398bb Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 16 Sep 2026 20:32:27 +1000 Subject: [PATCH] example: inspect SECCOMP_MODE_STRICT return value --- example/convert-to-nia/convert-to-nia.c | 7 +++++-- example/jsonptr/jsonptr.cc | 8 ++++++-- example/mzcat/mzcat.c | 8 ++++++-- example/zcat/zcat.c | 8 ++++++-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/example/convert-to-nia/convert-to-nia.c b/example/convert-to-nia/convert-to-nia.c index ef5abc7e..c7eac6ae 100644 --- a/example/convert-to-nia/convert-to-nia.c +++ b/example/convert-to-nia/convert-to-nia.c @@ -1098,8 +1098,11 @@ main(int argc, char** argv) { // ---- #if defined(WUFFS_EXAMPLE_USE_SECCOMP) - prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT); - g_sandboxed = true; + g_sandboxed = prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT) >= 0; + if (!g_sandboxed) { + const char* msg = "SECCOMP_MODE_STRICT sandbox failed.\n"; + ignore_return_value(write(STDERR_FD, msg, strlen(msg))); + } #endif int exit_code = compute_exit_code(main1(argc, argv)); diff --git a/example/jsonptr/jsonptr.cc b/example/jsonptr/jsonptr.cc index 7f9dc09f..e96381bb 100644 --- a/example/jsonptr/jsonptr.cc +++ b/example/jsonptr/jsonptr.cc @@ -1471,8 +1471,12 @@ main(int argc, char** argv) { } #if defined(WUFFS_EXAMPLE_USE_SECCOMP) - prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT); - g_sandboxed = true; + g_sandboxed = prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT) >= 0; + if (!g_sandboxed) { + const int stderr_fd = 2; + const char* msg = "SECCOMP_MODE_STRICT sandbox failed.\n"; + ignore_return_value(write(stderr_fd, msg, strlen(msg))); + } #endif const char* z = main1(argc, argv); diff --git a/example/mzcat/mzcat.c b/example/mzcat/mzcat.c index c622da05..04195bc3 100644 --- a/example/mzcat/mzcat.c +++ b/example/mzcat/mzcat.c @@ -397,8 +397,12 @@ print_crc32_digest(bool bad) { int // main(int argc, char** argv) { #if defined(WUFFS_EXAMPLE_USE_SECCOMP) - prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT); - g_sandboxed = true; + g_sandboxed = prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT) >= 0; + if (!g_sandboxed) { + const int stderr_fd = 2; + const char* msg = "SECCOMP_MODE_STRICT sandbox failed.\n"; + ignore_return_value(write(stderr_fd, msg, strlen(msg))); + } #endif int exit_code = compute_exit_code(main1(argc, argv)); diff --git a/example/zcat/zcat.c b/example/zcat/zcat.c index 8432f220..4323f9b3 100644 --- a/example/zcat/zcat.c +++ b/example/zcat/zcat.c @@ -260,8 +260,12 @@ compute_exit_code(const char* status_msg) { int // main(int argc, char** argv) { #if defined(WUFFS_EXAMPLE_USE_SECCOMP) - prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT); - g_sandboxed = true; + g_sandboxed = prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT) >= 0; + if (!g_sandboxed) { + const int stderr_fd = 2; + const char* msg = "SECCOMP_MODE_STRICT sandbox failed.\n"; + ignore_return_value(write(stderr_fd, msg, strlen(msg))); + } #endif int exit_code = compute_exit_code(main1(argc, argv));