From c3f581a06279d45330a9c325ecf6d963efd6023b Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 09:07:44 +0100 Subject: [PATCH 01/14] cmd: enable more compiler warnings Bump the number of warning issue by compiler. Signed-off-by: Maciej Borzecki --- cmd/Makefile.am | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/Makefile.am b/cmd/Makefile.am index 545dd7a8e78..943813cb240 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -7,6 +7,8 @@ dist_man_MANS = noinst_PROGRAMS = noinst_LIBRARIES = +CHECK_CFLAGS = -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes \ + -Wno-missing-field-initializers -Wno-unused-parameter subdirs = snap-confine snap-discard-ns system-shutdown libsnap-confine-private # Run check-syntax when checking @@ -190,7 +192,7 @@ snap_confine_snap_confine_SOURCES = \ snap-confine/user-support.c \ snap-confine/user-support.h -snap_confine_snap_confine_CFLAGS = -Wall -Werror $(AM_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" +snap_confine_snap_confine_CFLAGS = $(CHECK_CFLAGS) $(AM_CFLAGS) -DLIBEXECDIR=\"$(libexecdir)\" snap_confine_snap_confine_LDFLAGS = $(AM_LDFLAGS) snap_confine_snap_confine_LDADD = libsnap-confine-private.a snap_confine_snap_confine_CFLAGS += $(LIBUDEV_CFLAGS) @@ -362,7 +364,7 @@ snap_discard_ns_snap_discard_ns_SOURCES = \ snap-confine/apparmor-support.c \ snap-confine/apparmor-support.h \ snap-discard-ns/snap-discard-ns.c -snap_discard_ns_snap_discard_ns_CFLAGS = -Wall -Werror $(AM_CFLAGS) +snap_discard_ns_snap_discard_ns_CFLAGS = $(CHECK_CFLAGS) $(AM_CFLAGS) snap_discard_ns_snap_discard_ns_LDFLAGS = $(AM_LDFLAGS) snap_discard_ns_snap_discard_ns_LDADD = libsnap-confine-private.a snap_discard_ns_snap_discard_ns_STATIC = @@ -406,7 +408,7 @@ system_shutdown_system_shutdown_SOURCES = \ system-shutdown/system-shutdown-utils.h \ system-shutdown/system-shutdown.c system_shutdown_system_shutdown_LDADD = libsnap-confine-private.a -system_shutdown_system_shutdown_CFLAGS = $(filter-out -fPIE -pie,$(CFLAGS)) -static +system_shutdown_system_shutdown_CFLAGS = $(CHECK_CFLAGS) $(filter-out -fPIE -pie,$(CFLAGS)) -static system_shutdown_system_shutdown_LDFLAGS = $(filter-out -fPIE -pie,$(LDFLAGS)) -static if WITH_UNIT_TESTS From c6ceaeb4ff343416e67daaac6da7fe4700408808 Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 07:52:23 +0100 Subject: [PATCH 02/14] snap-confine, system-shutdown, libsnap-confine-private: use void when symbol takes no paramters, make symbols static MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure to use void in parameter list when a function takes no paramters. Otherwise the symbol can take any number of parameters. Where possible, make symbols static. Fixes 'function declaration isn’t a prototype [-Wstrict-prototypes]' warnings. Signed-off-by: Maciej Borzecki --- cmd/libsnap-confine-private/classic.h | 2 +- .../fault-injection-test.c | 4 +- cmd/libsnap-confine-private/fault-injection.c | 2 +- cmd/libsnap-confine-private/locking.c | 6 +-- cmd/libsnap-confine-private/locking.h | 6 +-- cmd/libsnap-confine-private/mount-opt-test.c | 12 ++--- cmd/libsnap-confine-private/mount-opt.c | 4 +- cmd/libsnap-confine-private/mountinfo-test.c | 16 +++--- cmd/libsnap-confine-private/mountinfo.c | 4 +- .../string-utils-test.c | 54 +++++++++---------- cmd/libsnap-confine-private/test-utils-test.c | 4 +- cmd/libsnap-confine-private/utils-test.c | 14 ++--- cmd/libsnap-confine-private/utils.c | 4 +- cmd/libsnap-confine-private/utils.h | 4 +- cmd/snap-confine/cookie-support-test.c | 8 +-- cmd/snap-confine/mount-support-test.c | 8 +-- cmd/snap-confine/mount-support.c | 6 +-- cmd/snap-confine/mount-support.h | 2 +- cmd/snap-confine/ns-support-test.c | 16 +++--- cmd/snap-confine/ns-support.c | 8 +-- cmd/snap-confine/ns-support.h | 4 +- cmd/snap-confine/quirks.c | 6 +-- cmd/snap-confine/quirks.h | 2 +- cmd/snap-confine/snap-confine-args-test.c | 32 +++++------ cmd/snap-confine/snap-confine.c | 4 +- cmd/snap-confine/udev-support.c | 2 +- cmd/snap-confine/user-support.c | 4 +- cmd/snap-confine/user-support.h | 4 +- cmd/system-shutdown/system-shutdown-utils.c | 2 +- cmd/system-shutdown/system-shutdown-utils.h | 2 +- 30 files changed, 123 insertions(+), 123 deletions(-) diff --git a/cmd/libsnap-confine-private/classic.h b/cmd/libsnap-confine-private/classic.h index 8927979ad92..f877140e273 100644 --- a/cmd/libsnap-confine-private/classic.h +++ b/cmd/libsnap-confine-private/classic.h @@ -22,6 +22,6 @@ // Location of the host filesystem directory in the core snap. #define SC_HOSTFS_DIR "/var/lib/snapd/hostfs" -bool is_running_on_classic_distribution(); +bool is_running_on_classic_distribution(void); #endif diff --git a/cmd/libsnap-confine-private/fault-injection-test.c b/cmd/libsnap-confine-private/fault-injection-test.c index 2815308e756..1d62f593e69 100644 --- a/cmd/libsnap-confine-private/fault-injection-test.c +++ b/cmd/libsnap-confine-private/fault-injection-test.c @@ -33,7 +33,7 @@ static bool broken_alter_msg(struct sc_fault_state *state, void *ptr) return true; } -static void test_fault_injection() +static void test_fault_injection(void) { g_assert_false(sc_faulty("foo", NULL)); @@ -57,7 +57,7 @@ static void test_fault_injection() sc_reset_faults(); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/fault-injection", test_fault_injection); } diff --git a/cmd/libsnap-confine-private/fault-injection.c b/cmd/libsnap-confine-private/fault-injection.c index 7a3d14d9389..c848684311f 100644 --- a/cmd/libsnap-confine-private/fault-injection.c +++ b/cmd/libsnap-confine-private/fault-injection.c @@ -57,7 +57,7 @@ void sc_break(const char *name, sc_fault_fn fn) sc_faults = fault; } -void sc_reset_faults() +void sc_reset_faults(void) { struct sc_fault *next_fault; for (struct sc_fault * fault = sc_faults; fault != NULL; diff --git a/cmd/libsnap-confine-private/locking.c b/cmd/libsnap-confine-private/locking.c index f0d923ce736..5d499f07c79 100644 --- a/cmd/libsnap-confine-private/locking.c +++ b/cmd/libsnap-confine-private/locking.c @@ -46,7 +46,7 @@ static void sc_SIGALRM_handler(int signum) sanity_timeout_expired = 1; } -void sc_enable_sanity_timeout() +void sc_enable_sanity_timeout(void) { sanity_timeout_expired = 0; struct sigaction act = {.sa_handler = sc_SIGALRM_handler }; @@ -64,7 +64,7 @@ void sc_enable_sanity_timeout() debug("sanity timeout initialized and set for three seconds"); } -void sc_disable_sanity_timeout() +void sc_disable_sanity_timeout(void) { if (sanity_timeout_expired) { die("sanity timeout expired"); @@ -134,7 +134,7 @@ void sc_unlock(const char *scope, int lock_fd) close(lock_fd); } -int sc_lock_global() +int sc_lock_global(void) { return sc_lock(NULL); } diff --git a/cmd/libsnap-confine-private/locking.h b/cmd/libsnap-confine-private/locking.h index da609cc816a..49e77b59377 100644 --- a/cmd/libsnap-confine-private/locking.h +++ b/cmd/libsnap-confine-private/locking.h @@ -50,7 +50,7 @@ void sc_unlock(const char *scope, int lock_fd); * This function is exactly like sc_lock(NULL), that is the acquired lock is * not specific to any snap but global. **/ -int sc_lock_global(); +int sc_lock_global(void); /** * Release a flock-based, globally scoped, lock @@ -71,7 +71,7 @@ void sc_unlock_global(int lock_fd); * disables the alarm and acts on the flag, aborting the process if the timeout * gets exceeded. **/ -void sc_enable_sanity_timeout(); +void sc_enable_sanity_timeout(void); /** * Disable sanity-check timeout and abort the process if it expired. @@ -79,6 +79,6 @@ void sc_enable_sanity_timeout(); * This call has to be paired with sc_enable_sanity_timeout(), see the function * description for more details. **/ -void sc_disable_sanity_timeout(); +void sc_disable_sanity_timeout(void); #endif // SNAP_CONFINE_LOCKING_H diff --git a/cmd/libsnap-confine-private/mount-opt-test.c b/cmd/libsnap-confine-private/mount-opt-test.c index a035b7b3798..76fd6a52258 100644 --- a/cmd/libsnap-confine-private/mount-opt-test.c +++ b/cmd/libsnap-confine-private/mount-opt-test.c @@ -23,7 +23,7 @@ #include -static void test_sc_mount_opt2str() +static void test_sc_mount_opt2str(void) { char buf[1000] = { 0 }; g_assert_cmpstr(sc_mount_opt2str(buf, sizeof buf, 0), ==, ""); @@ -91,7 +91,7 @@ static void test_sc_mount_opt2str() "ro,noexec,bind"); } -static void test_sc_mount_cmd() +static void test_sc_mount_cmd(void) { char cmd[10000] = { 0 }; @@ -174,7 +174,7 @@ static void test_sc_mount_cmd() g_assert_cmpstr(cmd, ==, expected); } -static void test_sc_umount_cmd() +static void test_sc_umount_cmd(void) { char cmd[1000] = { 0 }; @@ -205,7 +205,7 @@ static void test_sc_umount_cmd() "umount --force --lazy --expire --no-follow /mnt/foo"); } -static void test_sc_do_mount() +static void test_sc_do_mount(void) { if (g_test_subprocess()) { bool broken_mount(struct sc_fault_state *state, void *ptr) { @@ -226,7 +226,7 @@ static void test_sc_do_mount() ("cannot perform operation: mount -t ext4 -o ro /foo /bar: Permission denied\n"); } -static void test_sc_do_umount() +static void test_sc_do_umount(void) { if (g_test_subprocess()) { bool broken_umount(struct sc_fault_state *state, void *ptr) { @@ -247,7 +247,7 @@ static void test_sc_do_umount() ("cannot perform operation: umount --lazy /foo: Permission denied\n"); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/mount/sc_mount_opt2str", test_sc_mount_opt2str); g_test_add_func("/mount/sc_mount_cmd", test_sc_mount_cmd); diff --git a/cmd/libsnap-confine-private/mount-opt.c b/cmd/libsnap-confine-private/mount-opt.c index c96aa8e13b8..fa3065df858 100644 --- a/cmd/libsnap-confine-private/mount-opt.c +++ b/cmd/libsnap-confine-private/mount-opt.c @@ -252,7 +252,7 @@ void sc_do_mount(const char *source, const char *target, char buf[10000] = { 0 }; const char *mount_cmd = NULL; - void ensure_mount_cmd() { + void ensure_mount_cmd(void) { if (mount_cmd != NULL) { return; } @@ -291,7 +291,7 @@ void sc_do_umount(const char *target, int flags) char buf[10000] = { 0 }; const char *umount_cmd = NULL; - void ensure_umount_cmd() { + void ensure_umount_cmd(void) { if (umount_cmd != NULL) { return; } diff --git a/cmd/libsnap-confine-private/mountinfo-test.c b/cmd/libsnap-confine-private/mountinfo-test.c index 1fa35b7e3b6..180f1cacca0 100644 --- a/cmd/libsnap-confine-private/mountinfo-test.c +++ b/cmd/libsnap-confine-private/mountinfo-test.c @@ -20,7 +20,7 @@ #include -static void test_parse_mountinfo_entry__sysfs() +static void test_parse_mountinfo_entry__sysfs(void) { const char *line = "19 25 0:18 / /sys rw,nosuid,nodev,noexec,relatime shared:7 - sysfs sysfs rw"; @@ -44,7 +44,7 @@ static void test_parse_mountinfo_entry__sysfs() // Parse the /run/snapd/ns bind mount (over itself) // Note that /run is itself a tmpfs mount point. -static void test_parse_mountinfo_entry__snapd_ns() +static void test_parse_mountinfo_entry__snapd_ns(void) { const char *line = "104 23 0:19 /snapd/ns /run/snapd/ns rw,nosuid,noexec,relatime - tmpfs tmpfs rw,size=99840k,mode=755"; @@ -65,7 +65,7 @@ static void test_parse_mountinfo_entry__snapd_ns() g_assert_null(entry->next); } -static void test_parse_mountinfo_entry__snapd_mnt() +static void test_parse_mountinfo_entry__snapd_mnt(void) { const char *line = "256 104 0:3 mnt:[4026532509] /run/snapd/ns/hello-world.mnt rw - nsfs nsfs rw"; @@ -86,14 +86,14 @@ static void test_parse_mountinfo_entry__snapd_mnt() g_assert_null(entry->next); } -static void test_parse_mountinfo_entry__garbage() +static void test_parse_mountinfo_entry__garbage(void) { const char *line = "256 104 0:3"; struct sc_mountinfo_entry *entry = sc_parse_mountinfo_entry(line); g_assert_null(entry); } -static void test_parse_mountinfo_entry__no_tags() +static void test_parse_mountinfo_entry__no_tags(void) { const char *line = "1 2 3:4 root mount-dir mount-opts - fs-type mount-source super-opts"; @@ -114,7 +114,7 @@ static void test_parse_mountinfo_entry__no_tags() g_assert_null(entry->next); } -static void test_parse_mountinfo_entry__one_tag() +static void test_parse_mountinfo_entry__one_tag(void) { const char *line = "1 2 3:4 root mount-dir mount-opts tag:1 - fs-type mount-source super-opts"; @@ -135,7 +135,7 @@ static void test_parse_mountinfo_entry__one_tag() g_assert_null(entry->next); } -static void test_parse_mountinfo_entry__many_tags() +static void test_parse_mountinfo_entry__many_tags(void) { const char *line = "1 2 3:4 root mount-dir mount-opts tag:1 tag:2 tag:3 tag:4 - fs-type mount-source super-opts"; @@ -156,7 +156,7 @@ static void test_parse_mountinfo_entry__many_tags() g_assert_null(entry->next); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/mountinfo/parse_mountinfo_entry/sysfs", test_parse_mountinfo_entry__sysfs); diff --git a/cmd/libsnap-confine-private/mountinfo.c b/cmd/libsnap-confine-private/mountinfo.c index 1dac4226a26..5db3b309507 100644 --- a/cmd/libsnap-confine-private/mountinfo.c +++ b/cmd/libsnap-confine-private/mountinfo.c @@ -154,7 +154,7 @@ static struct sc_mountinfo_entry *sc_parse_mountinfo_entry(const char *line) goto fail; offset += offset_delta; - void show_buffers() { + void show_buffers(void) { #ifdef MOUNTINFO_DEBUG fprintf(stderr, "Input buffer (first), with offset arrow\n"); fprintf(stderr, "Output buffer (second)\n"); @@ -185,7 +185,7 @@ static struct sc_mountinfo_entry *sc_parse_mountinfo_entry(const char *line) show_buffers(); - char *parse_next_string_field() { + char *parse_next_string_field(void) { char *field = &entry->line_buf[0] + offset; int nscanned = sscanf(line + offset, "%s %n", field, &offset_delta); diff --git a/cmd/libsnap-confine-private/string-utils-test.c b/cmd/libsnap-confine-private/string-utils-test.c index b28538792c9..a2ee592ffe3 100644 --- a/cmd/libsnap-confine-private/string-utils-test.c +++ b/cmd/libsnap-confine-private/string-utils-test.c @@ -20,7 +20,7 @@ #include -static void test_sc_streq() +static void test_sc_streq(void) { g_assert_false(sc_streq(NULL, NULL)); g_assert_false(sc_streq(NULL, "text")); @@ -32,7 +32,7 @@ static void test_sc_streq() g_assert_true(sc_streq("", "")); } -static void test_sc_endswith() +static void test_sc_endswith(void) { // NULL doesn't end with anything, nothing ends with NULL g_assert_false(sc_endswith("", NULL)); @@ -53,14 +53,14 @@ static void test_sc_endswith() g_assert_false(sc_endswith("ba", "bar")); } -static void test_sc_must_snprintf() +static void test_sc_must_snprintf(void) { char buf[5] = { 0 }; sc_must_snprintf(buf, sizeof buf, "1234"); g_assert_cmpstr(buf, ==, "1234"); } -static void test_sc_must_snprintf__fail() +static void test_sc_must_snprintf__fail(void) { if (g_test_subprocess()) { char buf[5]; @@ -75,7 +75,7 @@ static void test_sc_must_snprintf__fail() } // Check that appending to a buffer works OK. -static void test_sc_string_append() +static void test_sc_string_append(void) { union { char bigbuf[6]; @@ -106,7 +106,7 @@ static void test_sc_string_append() } // Check that appending an empty string to a full buffer is valid. -static void test_sc_string_append__empty_to_full() +static void test_sc_string_append__empty_to_full(void) { union { char bigbuf[6]; @@ -137,7 +137,7 @@ static void test_sc_string_append__empty_to_full() } // Check that the overflow detection works. -static void test_sc_string_append__overflow() +static void test_sc_string_append__overflow(void) { if (g_test_subprocess()) { char buf[4] = { 0 }; @@ -156,7 +156,7 @@ static void test_sc_string_append__overflow() } // Check that the uninitialized buffer detection works. -static void test_sc_string_append__uninitialized_buf() +static void test_sc_string_append__uninitialized_buf(void) { if (g_test_subprocess()) { char buf[4] = { 0xFF, 0xFF, 0xFF, 0xFF }; @@ -175,7 +175,7 @@ static void test_sc_string_append__uninitialized_buf() } // Check that `buf' cannot be NULL. -static void test_sc_string_append__NULL_buf() +static void test_sc_string_append__NULL_buf(void) { if (g_test_subprocess()) { char buf[4]; @@ -192,7 +192,7 @@ static void test_sc_string_append__NULL_buf() } // Check that `src' cannot be NULL. -static void test_sc_string_append__NULL_str() +static void test_sc_string_append__NULL_str(void) { if (g_test_subprocess()) { char buf[4]; @@ -208,7 +208,7 @@ static void test_sc_string_append__NULL_str() g_test_trap_assert_stderr("cannot append string: string is NULL\n"); } -static void test_sc_string_init__normal() +static void test_sc_string_init__normal(void) { char buf[1] = { 0xFF }; @@ -216,7 +216,7 @@ static void test_sc_string_init__normal() g_assert_cmpint(buf[0], ==, 0); } -static void test_sc_string_init__empty_buf() +static void test_sc_string_init__empty_buf(void) { if (g_test_subprocess()) { char buf[1] = { 0xFF }; @@ -233,7 +233,7 @@ static void test_sc_string_init__empty_buf() ("cannot initialize string, buffer is too small\n"); } -static void test_sc_string_init__NULL_buf() +static void test_sc_string_init__NULL_buf(void) { if (g_test_subprocess()) { sc_string_init(NULL, 1); @@ -247,7 +247,7 @@ static void test_sc_string_init__NULL_buf() g_test_trap_assert_stderr("cannot initialize string, buffer is NULL\n"); } -static void test_sc_string_append_char__uninitialized_buf() +static void test_sc_string_append_char__uninitialized_buf(void) { if (g_test_subprocess()) { char buf[2] = { 0xFF, 0xFF }; @@ -263,7 +263,7 @@ static void test_sc_string_append_char__uninitialized_buf() ("cannot append character: dst is unterminated\n"); } -static void test_sc_string_append_char__NULL_buf() +static void test_sc_string_append_char__NULL_buf(void) { if (g_test_subprocess()) { sc_string_append_char(NULL, 2, 'a'); @@ -277,7 +277,7 @@ static void test_sc_string_append_char__NULL_buf() g_test_trap_assert_stderr("cannot append character: buffer is NULL\n"); } -static void test_sc_string_append_char__overflow() +static void test_sc_string_append_char__overflow(void) { if (g_test_subprocess()) { char buf[1] = { 0 }; @@ -293,7 +293,7 @@ static void test_sc_string_append_char__overflow() ("cannot append character: not enough space\n"); } -static void test_sc_string_append_char__invalid_zero() +static void test_sc_string_append_char__invalid_zero(void) { if (g_test_subprocess()) { char buf[2] = { 0 }; @@ -309,7 +309,7 @@ static void test_sc_string_append_char__invalid_zero() ("cannot append character: cannot append string terminator\n"); } -static void test_sc_string_append_char__normal() +static void test_sc_string_append_char__normal(void) { char buf[16]; size_t len; @@ -332,7 +332,7 @@ static void test_sc_string_append_char__normal() g_assert_cmpint(len, ==, 5); } -static void test_sc_string_append_char_pair__uninitialized_buf() +static void test_sc_string_append_char_pair__uninitialized_buf(void) { if (g_test_subprocess()) { char buf[3] = { 0xFF, 0xFF, 0xFF }; @@ -349,7 +349,7 @@ static void test_sc_string_append_char_pair__uninitialized_buf() ("cannot append character pair: dst is unterminated\n"); } -static void test_sc_string_append_char_pair__NULL_buf() +static void test_sc_string_append_char_pair__NULL_buf(void) { if (g_test_subprocess()) { sc_string_append_char_pair(NULL, 3, 'a', 'b'); @@ -365,7 +365,7 @@ static void test_sc_string_append_char_pair__NULL_buf() ("cannot append character pair: buffer is NULL\n"); } -static void test_sc_string_append_char_pair__overflow() +static void test_sc_string_append_char_pair__overflow(void) { if (g_test_subprocess()) { char buf[2] = { 0 }; @@ -382,7 +382,7 @@ static void test_sc_string_append_char_pair__overflow() ("cannot append character pair: not enough space\n"); } -static void test_sc_string_append_char_pair__invalid_zero_c1() +static void test_sc_string_append_char_pair__invalid_zero_c1(void) { if (g_test_subprocess()) { char buf[3] = { 0 }; @@ -399,7 +399,7 @@ static void test_sc_string_append_char_pair__invalid_zero_c1() ("cannot append character pair: cannot append string terminator\n"); } -static void test_sc_string_append_char_pair__invalid_zero_c2() +static void test_sc_string_append_char_pair__invalid_zero_c2(void) { if (g_test_subprocess()) { char buf[3] = { 0 }; @@ -416,7 +416,7 @@ static void test_sc_string_append_char_pair__invalid_zero_c2() ("cannot append character pair: cannot append string terminator\n"); } -static void test_sc_string_append_char_pair__normal() +static void test_sc_string_append_char_pair__normal(void) { char buf[16]; size_t len; @@ -433,7 +433,7 @@ static void test_sc_string_append_char_pair__normal() g_assert_cmpint(len, ==, 6); } -static void test_sc_string_quote_NULL_str() +static void test_sc_string_quote_NULL_str(void) { if (g_test_subprocess()) { char buf[16] = { 0 }; @@ -448,7 +448,7 @@ static void test_sc_string_quote_NULL_str() g_test_trap_assert_stderr("cannot quote string: string is NULL\n"); } -static void test_sc_string_quote() +static void test_sc_string_quote(void) { #define DQ "\"" char buf[16]; @@ -777,7 +777,7 @@ static void test_sc_string_quote() #undef DQ } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/string-utils/sc_streq", test_sc_streq); g_test_add_func("/string-utils/sc_endswith", test_sc_endswith); diff --git a/cmd/libsnap-confine-private/test-utils-test.c b/cmd/libsnap-confine-private/test-utils-test.c index be0e0191b8d..04894c454b2 100644 --- a/cmd/libsnap-confine-private/test-utils-test.c +++ b/cmd/libsnap-confine-private/test-utils-test.c @@ -23,7 +23,7 @@ #include // Check that rm_rf_tmp doesn't remove things outside of /tmp -static void test_rm_rf_tmp() +static void test_rm_rf_tmp(void) { if (access("/nonexistent", F_OK) == 0) { g_test_message @@ -39,7 +39,7 @@ static void test_rm_rf_tmp() g_test_trap_assert_failed(); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/test-utils/rm_rf_tmp", test_rm_rf_tmp); } diff --git a/cmd/libsnap-confine-private/utils-test.c b/cmd/libsnap-confine-private/utils-test.c index b8ee8ca9beb..e878260622c 100644 --- a/cmd/libsnap-confine-private/utils-test.c +++ b/cmd/libsnap-confine-private/utils-test.c @@ -20,7 +20,7 @@ #include -static void test_parse_bool() +static void test_parse_bool(void) { int err; bool value; @@ -71,7 +71,7 @@ static void test_parse_bool() g_assert_cmpint(errno, ==, EFAULT); } -static void test_die() +static void test_die(void) { if (g_test_subprocess()) { errno = 0; @@ -85,7 +85,7 @@ static void test_die() g_test_trap_assert_stderr("death message\n"); } -static void test_die_with_errno() +static void test_die_with_errno(void) { if (g_test_subprocess()) { errno = EPERM; @@ -106,7 +106,7 @@ static void test_die_with_errno() * operations at the end of the test. If any additional directories or files * are created in this directory they must be removed by the caller. **/ -static void g_test_in_ephemeral_dir() +static void g_test_in_ephemeral_dir(void) { gchar *temp_dir = g_dir_make_tmp(NULL, NULL); gchar *orig_dir = g_get_current_dir(); @@ -152,7 +152,7 @@ static void _test_sc_nonfatal_mkpath(const gchar * dirname, /** * Test that sc_nonfatal_mkpath behaves when using relative paths. **/ -static void test_sc_nonfatal_mkpath__relative() +static void test_sc_nonfatal_mkpath__relative(void) { g_test_in_ephemeral_dir(); gchar *current_dir = g_get_current_dir(); @@ -167,7 +167,7 @@ static void test_sc_nonfatal_mkpath__relative() /** * Test that sc_nonfatal_mkpath behaves when using absolute paths. **/ -static void test_sc_nonfatal_mkpath__absolute() +static void test_sc_nonfatal_mkpath__absolute(void) { g_test_in_ephemeral_dir(); const char *dirname = "foo"; @@ -175,7 +175,7 @@ static void test_sc_nonfatal_mkpath__absolute() _test_sc_nonfatal_mkpath(dirname, subdirname); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/utils/parse_bool", test_parse_bool); g_test_add_func("/utils/die", test_die); diff --git a/cmd/libsnap-confine-private/utils.c b/cmd/libsnap-confine-private/utils.c index d8bfc0dcfbe..2f4d5d57763 100644 --- a/cmd/libsnap-confine-private/utils.c +++ b/cmd/libsnap-confine-private/utils.c @@ -119,13 +119,13 @@ static bool getenv_bool(const char *name, bool default_value) return value; } -bool sc_is_debug_enabled() +bool sc_is_debug_enabled(void) { return getenv_bool("SNAP_CONFINE_DEBUG", false) || getenv_bool("SNAPD_DEBUG", false); } -bool sc_is_reexec_enabled() +bool sc_is_reexec_enabled(void) { return getenv_bool("SNAP_REEXEC", true); } diff --git a/cmd/libsnap-confine-private/utils.h b/cmd/libsnap-confine-private/utils.h index 94ef3ae1602..b544f6cfa70 100644 --- a/cmd/libsnap-confine-private/utils.h +++ b/cmd/libsnap-confine-private/utils.h @@ -35,12 +35,12 @@ void debug(const char *fmt, ...); * * This can used to avoid costly computation that is only useful for debugging. **/ -bool sc_is_debug_enabled(); +bool sc_is_debug_enabled(void); /** * Return true if re-execution is enabled. **/ -bool sc_is_reexec_enabled(); +bool sc_is_reexec_enabled(void); void write_string_to_file(const char *filepath, const char *buf); diff --git a/cmd/snap-confine/cookie-support-test.c b/cmd/snap-confine/cookie-support-test.c index 4011090033c..b5f382ca6bd 100644 --- a/cmd/snap-confine/cookie-support-test.c +++ b/cmd/snap-confine/cookie-support-test.c @@ -31,7 +31,7 @@ static void set_cookie_dir(const char *dir) sc_cookie_dir = dir; } -static void set_fake_cookie_dir() +static void set_fake_cookie_dir(void) { char *ctx_dir = NULL; ctx_dir = g_dir_make_tmp(NULL, NULL); @@ -62,7 +62,7 @@ static void create_dumy_cookie_file(const char *snap_name, fclose(f); } -static void test_cookie_get_from_snapd__successful() +static void test_cookie_get_from_snapd__successful(void) { struct sc_error *err = NULL; char *cookie; @@ -79,7 +79,7 @@ static void test_cookie_get_from_snapd__successful() g_assert_cmpstr(cookie, ==, dummy); } -static void test_cookie_get_from_snapd__nofile() +static void test_cookie_get_from_snapd__nofile(void) { struct sc_error *err = NULL; char *cookie; @@ -93,7 +93,7 @@ static void test_cookie_get_from_snapd__nofile() g_assert_null(cookie); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/snap-cookie/cookie_get_from_snapd/successful", test_cookie_get_from_snapd__successful); diff --git a/cmd/snap-confine/mount-support-test.c b/cmd/snap-confine/mount-support-test.c index da3cf80c3c0..a57016a56be 100644 --- a/cmd/snap-confine/mount-support-test.c +++ b/cmd/snap-confine/mount-support-test.c @@ -30,7 +30,7 @@ static void replace_slashes_with_NUL(char *path, size_t len) } } -static void test_get_nextpath__typical() +static void test_get_nextpath__typical(void) { char path[] = "/some/path"; size_t offset = 0; @@ -50,7 +50,7 @@ static void test_get_nextpath__typical() g_assert_cmpstr(result, ==, NULL); } -static void test_get_nextpath__weird() +static void test_get_nextpath__weird(void) { char path[] = "..///path"; size_t offset = 0; @@ -68,7 +68,7 @@ static void test_get_nextpath__weird() g_assert_cmpstr(result, ==, NULL); } -static void test_is_subdir() +static void test_is_subdir(void) { // Sensible exaples are sensible g_assert_true(is_subdir("/dir/subdir", "/dir/")); @@ -91,7 +91,7 @@ static void test_is_subdir() g_assert_false(is_subdir("/", "")); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/mount/get_nextpath/typical", test_get_nextpath__typical); diff --git a/cmd/snap-confine/mount-support.c b/cmd/snap-confine/mount-support.c index 4a96df26861..e948152fbdb 100644 --- a/cmd/snap-confine/mount-support.c +++ b/cmd/snap-confine/mount-support.c @@ -109,7 +109,7 @@ static void setup_private_mount(const char *snap_name) } // TODO: fold this into bootstrap -static void setup_private_pts() +static void setup_private_pts(void) { // See https://www.kernel.org/doc/Documentation/filesystems/devpts.txt // @@ -535,7 +535,7 @@ static bool __attribute__ ((used)) return false; } -static int sc_open_snap_update_ns() +static int sc_open_snap_update_ns(void) { // +1 is for the case where the link is exactly PATH_MAX long but we also // want to store the terminating '\0'. The readlink system call doesn't add @@ -703,7 +703,7 @@ static bool is_mounted_with_shared_option(const char *dir) return false; } -void sc_ensure_shared_snap_mount() +void sc_ensure_shared_snap_mount(void) { if (!is_mounted_with_shared_option("/") && !is_mounted_with_shared_option(SNAP_MOUNT_DIR)) { diff --git a/cmd/snap-confine/mount-support.h b/cmd/snap-confine/mount-support.h index 988e16d5a9d..ebeee838b5b 100644 --- a/cmd/snap-confine/mount-support.h +++ b/cmd/snap-confine/mount-support.h @@ -40,5 +40,5 @@ void sc_populate_mount_ns(const char *base_snap_name, const char *snap_name); * snap-confine will create a shared bind mount for "/snap" to * ensure that "/snap" is mounted shared. See LP:#1668659 */ -void sc_ensure_shared_snap_mount(); +void sc_ensure_shared_snap_mount(void); #endif diff --git a/cmd/snap-confine/ns-support-test.c b/cmd/snap-confine/ns-support-test.c index 720f82aac1a..542136cfb4a 100644 --- a/cmd/snap-confine/ns-support-test.c +++ b/cmd/snap-confine/ns-support-test.c @@ -39,7 +39,7 @@ static void sc_set_ns_dir(const char *dir) // // The directory is automatically reset to the real value at the end of the // test. -static const char *sc_test_use_fake_ns_dir() +static const char *sc_test_use_fake_ns_dir(void) { char *ns_dir = NULL; if (g_test_subprocess()) { @@ -64,7 +64,7 @@ static const char *sc_test_use_fake_ns_dir() // Check that allocating a namespace group sets up internal data structures to // safe values. -static void test_sc_alloc_ns_group() +static void test_sc_alloc_ns_group(void) { struct sc_ns_group *group = NULL; group = sc_alloc_ns_group(); @@ -101,7 +101,7 @@ static struct sc_ns_group *sc_test_open_ns_group(const char *group_name) // Check that initializing a namespace group creates the appropriate // filesystem structure. -static void test_sc_open_ns_group() +static void test_sc_open_ns_group(void) { const char *ns_dir = sc_test_use_fake_ns_dir(); sc_test_open_ns_group(NULL); @@ -110,7 +110,7 @@ static void test_sc_open_ns_group() (ns_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)); } -static void test_sc_open_ns_group_graceful() +static void test_sc_open_ns_group_graceful(void) { sc_set_ns_dir("/nonexistent"); g_test_queue_destroy((GDestroyNotify) sc_set_ns_dir, SC_NS_DIR); @@ -124,7 +124,7 @@ static void unmount_dir(void *dir) umount(dir); } -static void test_sc_is_ns_group_dir_private() +static void test_sc_is_ns_group_dir_private(void) { if (geteuid() != 0) { g_test_skip("this test needs to run as root"); @@ -152,7 +152,7 @@ static void test_sc_is_ns_group_dir_private() g_test_trap_assert_passed(); } -static void test_sc_initialize_ns_groups() +static void test_sc_initialize_ns_groups(void) { if (geteuid() != 0) { g_test_skip("this test needs to run as root"); @@ -174,7 +174,7 @@ static void test_sc_initialize_ns_groups() // Sanity check, ensure that the namespace filesystem identifier is what we // expect, aka NSFS_MAGIC. -static void test_nsfs_fs_id() +static void test_nsfs_fs_id(void) { struct utsname uts; if (uname(&uts) < 0) { @@ -198,7 +198,7 @@ static void test_nsfs_fs_id() g_assert_cmpint(buf.f_type, ==, NSFS_MAGIC); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/ns/sc_alloc_ns_group", test_sc_alloc_ns_group); g_test_add_func("/ns/sc_open_ns_group", test_sc_open_ns_group); diff --git a/cmd/snap-confine/ns-support.c b/cmd/snap-confine/ns-support.c index a950f835498..e6d0587a723 100644 --- a/cmd/snap-confine/ns-support.c +++ b/cmd/snap-confine/ns-support.c @@ -77,7 +77,7 @@ static const char *sc_ns_dir = SC_NS_DIR; * We do this because /run/snapd/ns cannot be shared with any other peers as per: * https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt **/ -static bool sc_is_ns_group_dir_private() +static bool sc_is_ns_group_dir_private(void) { struct sc_mountinfo *info SC_CLEANUP(sc_cleanup_mountinfo) = NULL; info = sc_parse_mountinfo(NULL); @@ -99,7 +99,7 @@ static bool sc_is_ns_group_dir_private() return false; } -void sc_reassociate_with_pid1_mount_ns() +void sc_reassociate_with_pid1_mount_ns(void) { int init_mnt_fd SC_CLEANUP(sc_cleanup_close) = -1; int self_mnt_fd SC_CLEANUP(sc_cleanup_close) = -1; @@ -155,7 +155,7 @@ void sc_reassociate_with_pid1_mount_ns() } } -void sc_initialize_ns_groups() +void sc_initialize_ns_groups(void) { debug("creating namespace group directory %s", sc_ns_dir); if (sc_nonfatal_mkpath(sc_ns_dir, 0755) < 0) { @@ -195,7 +195,7 @@ struct sc_ns_group { bool should_populate; }; -static struct sc_ns_group *sc_alloc_ns_group() +static struct sc_ns_group *sc_alloc_ns_group(void) { struct sc_ns_group *group = calloc(1, sizeof *group); if (group == NULL) { diff --git a/cmd/snap-confine/ns-support.h b/cmd/snap-confine/ns-support.h index 9694b1a2db1..bf2c8dcf7ce 100644 --- a/cmd/snap-confine/ns-support.h +++ b/cmd/snap-confine/ns-support.h @@ -31,7 +31,7 @@ * * This function should be called before sc_initialize_ns_groups(). **/ -void sc_reassociate_with_pid1_mount_ns(); +void sc_reassociate_with_pid1_mount_ns(void); /** * Initialize namespace sharing. @@ -54,7 +54,7 @@ void sc_reassociate_with_pid1_mount_ns(); * * For more details see namespaces(7). **/ -void sc_initialize_ns_groups(); +void sc_initialize_ns_groups(void); /** * Data required to manage namespaces amongst a group of processes. diff --git a/cmd/snap-confine/quirks.c b/cmd/snap-confine/quirks.c index 7fd0230c3c1..a7df77826a2 100644 --- a/cmd/snap-confine/quirks.c +++ b/cmd/snap-confine/quirks.c @@ -40,7 +40,7 @@ * (legacy). The mount point does not depend on build-time configuration and * does not differ from distribution to distribution. **/ -static const char *sc_get_inner_core_mount_point() +static const char *sc_get_inner_core_mount_point(void) { const char *core_path = "/snap/core/current/"; const char *ubuntu_core_path = "/snap/ubuntu-core/current/"; @@ -176,7 +176,7 @@ static void sc_quirk_create_writable_mimic(const char *mimic_dir, * * See: https://bugs.launchpad.net/snap-confine/+bug/1613845 **/ -static void sc_setup_lxd_quirk() +static void sc_setup_lxd_quirk(void) { const char *hostfs_lxd_dir = SC_HOSTFS_DIR "/var/lib/lxd"; if (access(hostfs_lxd_dir, F_OK) == 0) { @@ -188,7 +188,7 @@ static void sc_setup_lxd_quirk() } } -void sc_setup_quirks() +void sc_setup_quirks(void) { // because /var/lib/snapd is essential let's move it to /tmp/snapd for a sec char snapd_tmp[] = "/tmp/snapd.quirks_XXXXXX"; diff --git a/cmd/snap-confine/quirks.h b/cmd/snap-confine/quirks.h index 3d323d735d3..f707423bc8e 100644 --- a/cmd/snap-confine/quirks.h +++ b/cmd/snap-confine/quirks.h @@ -25,6 +25,6 @@ * because of requirement to stay compatible with certain snaps * that were tested with pre-chroot layout. **/ -void sc_setup_quirks(); +void sc_setup_quirks(void); #endif diff --git a/cmd/snap-confine/snap-confine-args-test.c b/cmd/snap-confine/snap-confine-args-test.c index c752586aac0..05d44ad4828 100644 --- a/cmd/snap-confine/snap-confine-args-test.c +++ b/cmd/snap-confine/snap-confine-args-test.c @@ -56,7 +56,7 @@ static void *argvp = argv; } -static void test_test_argc_argv() +static void test_test_argc_argv(void) { // Check that test_argc_argv() correctly stores data int argc; @@ -74,7 +74,7 @@ static void test_test_argc_argv() g_assert_null(argv[3]); } -static void test_sc_nonfatal_parse_args__typical() +static void test_sc_nonfatal_parse_args__typical(void) { // Test that typical invocation of snap-confine is parsed correctly. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -107,7 +107,7 @@ static void test_sc_nonfatal_parse_args__typical() g_assert_null(argv[3]); } -static void test_sc_cleanup_args() +static void test_sc_cleanup_args(void) { // Check that NULL argument parser can be cleaned up struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -128,7 +128,7 @@ static void test_sc_cleanup_args() g_assert_null(args); } -static void test_sc_nonfatal_parse_args__typical_classic() +static void test_sc_nonfatal_parse_args__typical_classic(void) { // Test that typical invocation of snap-confine is parsed correctly. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -161,7 +161,7 @@ static void test_sc_nonfatal_parse_args__typical_classic() g_assert_null(argv[3]); } -static void test_sc_nonfatal_parse_args__ubuntu_core_launcher() +static void test_sc_nonfatal_parse_args__ubuntu_core_launcher(void) { // Test that typical legacy invocation of snap-confine via the // ubuntu-core-launcher symlink, with duplicated security tag, is parsed @@ -196,7 +196,7 @@ static void test_sc_nonfatal_parse_args__ubuntu_core_launcher() g_assert_null(argv[3]); } -static void test_sc_nonfatal_parse_args__version() +static void test_sc_nonfatal_parse_args__version(void) { // Test that snap-confine --version is detected. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -226,7 +226,7 @@ static void test_sc_nonfatal_parse_args__version() g_assert_null(argv[3]); } -static void test_sc_nonfatal_parse_args__evil_input() +static void test_sc_nonfatal_parse_args__evil_input(void) { // Check that calling without any arguments is reported as error. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -266,7 +266,7 @@ static void test_sc_nonfatal_parse_args__evil_input() "cannot parse arguments, argument at index 1 is NULL"); } -static void test_sc_nonfatal_parse_args__nothing_to_parse() +static void test_sc_nonfatal_parse_args__nothing_to_parse(void) { // Check that calling without any arguments is reported as error. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -285,7 +285,7 @@ static void test_sc_nonfatal_parse_args__nothing_to_parse() "cannot parse arguments, argc is zero or argv is NULL"); } -static void test_sc_nonfatal_parse_args__no_security_tag() +static void test_sc_nonfatal_parse_args__no_security_tag(void) { // Check that lack of security tag is reported as error. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -307,7 +307,7 @@ static void test_sc_nonfatal_parse_args__no_security_tag() g_assert_true(sc_error_match(err, SC_ARGS_DOMAIN, SC_ARGS_ERR_USAGE)); } -static void test_sc_nonfatal_parse_args__no_executable() +static void test_sc_nonfatal_parse_args__no_executable(void) { // Check that lack of security tag is reported as error. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -329,7 +329,7 @@ static void test_sc_nonfatal_parse_args__no_executable() g_assert_true(sc_error_match(err, SC_ARGS_DOMAIN, SC_ARGS_ERR_USAGE)); } -static void test_sc_nonfatal_parse_args__unknown_option() +static void test_sc_nonfatal_parse_args__unknown_option(void) { // Check that unrecognized option switch is reported as error. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -351,7 +351,7 @@ static void test_sc_nonfatal_parse_args__unknown_option() g_assert_true(sc_error_match(err, SC_ARGS_DOMAIN, SC_ARGS_ERR_USAGE)); } -static void test_sc_nonfatal_parse_args__forwards_error() +static void test_sc_nonfatal_parse_args__forwards_error(void) { // Check that sc_nonfatal_parse_args() forwards errors. if (g_test_subprocess()) { @@ -376,7 +376,7 @@ static void test_sc_nonfatal_parse_args__forwards_error() "\nunrecognized command line option: --frozbonicator\n"); } -static void test_sc_nonfatal_parse_args__base_snap() +static void test_sc_nonfatal_parse_args__base_snap(void) { // Check that --base specifies the name of the base snap. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -404,7 +404,7 @@ static void test_sc_nonfatal_parse_args__base_snap() g_assert_cmpint(sc_args_is_classic_confinement(args), ==, false); } -static void test_sc_nonfatal_parse_args__base_snap__missing_arg() +static void test_sc_nonfatal_parse_args__base_snap__missing_arg(void) { // Check that --base specifies the name of the base snap. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -426,7 +426,7 @@ static void test_sc_nonfatal_parse_args__base_snap__missing_arg() g_assert_true(sc_error_match(err, SC_ARGS_DOMAIN, SC_ARGS_ERR_USAGE)); } -static void test_sc_nonfatal_parse_args__base_snap__twice() +static void test_sc_nonfatal_parse_args__base_snap__twice(void) { // Check that --base specifies the name of the base snap. struct sc_error *err SC_CLEANUP(sc_cleanup_error) = NULL; @@ -449,7 +449,7 @@ static void test_sc_nonfatal_parse_args__base_snap__twice() g_assert_true(sc_error_match(err, SC_ARGS_DOMAIN, SC_ARGS_ERR_USAGE)); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/args/test_argc_argv", test_test_argc_argv); g_test_add_func("/args/sc_cleanup_args", test_sc_cleanup_args); diff --git a/cmd/snap-confine/snap-confine.c b/cmd/snap-confine/snap-confine.c index 59a4e51bb6b..bea7be063cf 100644 --- a/cmd/snap-confine/snap-confine.c +++ b/cmd/snap-confine/snap-confine.c @@ -48,7 +48,7 @@ // sc_maybe_fixup_permissions fixes incorrect permissions // inside the mount namespace for /var/lib. Before 1ccce4 // this directory was created with permissions 1777. -void sc_maybe_fixup_permissions() +static void sc_maybe_fixup_permissions(void) { struct stat buf; if (stat("/var/lib", &buf) != 0) { @@ -68,7 +68,7 @@ void sc_maybe_fixup_permissions() // that cause libudev on 16.04 to fail with "udev_enumerate_scan failed". // See also: // https://forum.snapcraft.io/t/weird-udev-enumerate-error/2360/17 -void sc_maybe_fixup_udev() +static void sc_maybe_fixup_udev(void) { glob_t glob_res SC_CLEANUP(globfree) = { .gl_pathv = NULL,.gl_pathc = 0,.gl_offs = 0,}; diff --git a/cmd/snap-confine/udev-support.c b/cmd/snap-confine/udev-support.c index d7132b2cedd..e5408888615 100644 --- a/cmd/snap-confine/udev-support.c +++ b/cmd/snap-confine/udev-support.c @@ -32,7 +32,7 @@ #include "../libsnap-confine-private/utils.h" #include "udev-support.h" -void +static void _run_snappy_app_dev_add_majmin(struct snappy_udev *udev_s, const char *path, unsigned major, unsigned minor) { diff --git a/cmd/snap-confine/user-support.c b/cmd/snap-confine/user-support.c index c092370ca2a..fee292ed0f3 100644 --- a/cmd/snap-confine/user-support.c +++ b/cmd/snap-confine/user-support.c @@ -23,7 +23,7 @@ #include "../libsnap-confine-private/utils.h" -void setup_user_data() +void setup_user_data(void) { const char *user_data = getenv("SNAP_USER_DATA"); @@ -41,7 +41,7 @@ void setup_user_data() }; } -void setup_user_xdg_runtime_dir() +void setup_user_xdg_runtime_dir(void) { const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"); diff --git a/cmd/snap-confine/user-support.h b/cmd/snap-confine/user-support.h index 32f4e2f3618..859d04dd24e 100644 --- a/cmd/snap-confine/user-support.h +++ b/cmd/snap-confine/user-support.h @@ -18,8 +18,8 @@ #ifndef SNAP_CONFINE_USER_SUPPORT_H #define SNAP_CONFINE_USER_SUPPORT_H -void setup_user_data(); -void setup_user_xdg_runtime_dir(); +void setup_user_data(void); +void setup_user_xdg_runtime_dir(void); void mkpath(const char *const path); #endif diff --git a/cmd/system-shutdown/system-shutdown-utils.c b/cmd/system-shutdown/system-shutdown-utils.c index 04ed283e853..f46537b395d 100644 --- a/cmd/system-shutdown/system-shutdown-utils.c +++ b/cmd/system-shutdown/system-shutdown-utils.c @@ -105,7 +105,7 @@ static void detach_loop(const char *src) // tries to umount all (well, most) things. Returns whether in the last pass it // no longer found writable. -bool umount_all() +bool umount_all(void) { bool did_umount = true; bool had_writable = false; diff --git a/cmd/system-shutdown/system-shutdown-utils.h b/cmd/system-shutdown/system-shutdown-utils.h index ab590afdaa7..42f0349c721 100644 --- a/cmd/system-shutdown/system-shutdown-utils.h +++ b/cmd/system-shutdown/system-shutdown-utils.h @@ -23,7 +23,7 @@ // tries to umount all (well, most) things. Returns whether in the last pass it // no longer found writable. -bool umount_all(); +bool umount_all(void); __attribute__ ((noreturn)) void die(const char *msg); From 1e407d323060298fb2516e40882b4bf532081ec0 Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 07:53:39 +0100 Subject: [PATCH 03/14] snap-confine: fix comparison of signed with unsigned Signed-off-by: Maciej Borzecki --- cmd/snap-confine/mount-support.c | 2 +- cmd/snap-confine/udev-support.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/snap-confine/mount-support.c b/cmd/snap-confine/mount-support.c index e948152fbdb..e78b9a058ed 100644 --- a/cmd/snap-confine/mount-support.c +++ b/cmd/snap-confine/mount-support.c @@ -489,7 +489,7 @@ static void sc_bootstrap_mount_namespace(const struct sc_mount_config *config) static char * __attribute__ ((used)) get_nextpath(char *path, size_t * offsetp, size_t fulllen) { - int offset = *offsetp; + size_t offset = *offsetp; if (offset >= fulllen) return NULL; diff --git a/cmd/snap-confine/udev-support.c b/cmd/snap-confine/udev-support.c index e5408888615..9054ca99a4b 100644 --- a/cmd/snap-confine/udev-support.c +++ b/cmd/snap-confine/udev-support.c @@ -111,7 +111,7 @@ int snappy_udev_init(const char *security_tag, struct snappy_udev *udev_s) // TAG+="snap_" (udev doesn't like '.' in the tag name) udev_s->tagname_len = sc_must_snprintf(udev_s->tagname, MAX_BUF, "%s", security_tag); - for (int i = 0; i < udev_s->tagname_len; i++) + for (size_t i = 0; i < udev_s->tagname_len; i++) if (udev_s->tagname[i] == '.') udev_s->tagname[i] = '_'; From 668b676386fbf735d6be0a52373c4ff82bb91a63 Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 07:55:53 +0100 Subject: [PATCH 04/14] libsnap-confine-private: fix comparison of signed with unsigned Signed-off-by: Maciej Borzecki --- cmd/libsnap-confine-private/snap-test.c | 5 +++-- cmd/libsnap-confine-private/string-utils.c | 2 +- cmd/libsnap-confine-private/utils.c | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/libsnap-confine-private/snap-test.c b/cmd/libsnap-confine-private/snap-test.c index a5aa8d439ab..b09fecdf459 100644 --- a/cmd/libsnap-confine-private/snap-test.c +++ b/cmd/libsnap-confine-private/snap-test.c @@ -144,7 +144,7 @@ static void test_sc_snap_name_validate() "a0", "a-0", "a-0a", "01game", "1-or-2" }; - for (int i = 0; i < sizeof valid_names / sizeof *valid_names; ++i) { + for (size_t i = 0; i < sizeof valid_names / sizeof *valid_names; ++i) { g_test_message("checking valid snap name: %s", valid_names[i]); sc_snap_name_validate(valid_names[i], &err); g_assert_null(err); @@ -165,7 +165,8 @@ static void test_sc_snap_name_validate() // identifier must be plain ASCII "日本語", "한글", "ру́сский язы́к", }; - for (int i = 0; i < sizeof invalid_names / sizeof *invalid_names; ++i) { + for (size_t i = 0; i < sizeof invalid_names / sizeof *invalid_names; + ++i) { g_test_message("checking invalid snap name: >%s<", invalid_names[i]); sc_snap_name_validate(invalid_names[i], &err); diff --git a/cmd/libsnap-confine-private/string-utils.c b/cmd/libsnap-confine-private/string-utils.c index 23940325ebe..0c9c8ee4c24 100644 --- a/cmd/libsnap-confine-private/string-utils.c +++ b/cmd/libsnap-confine-private/string-utils.c @@ -65,7 +65,7 @@ int sc_must_snprintf(char *str, size_t size, const char *format, ...) n = vsnprintf(str, size, format, va); va_end(va); - if (n < 0 || n >= size) + if (n < 0 || (size_t) n >= size) die("cannot format string: %s", str); return n; diff --git a/cmd/libsnap-confine-private/utils.c b/cmd/libsnap-confine-private/utils.c index 2f4d5d57763..c0170eae73b 100644 --- a/cmd/libsnap-confine-private/utils.c +++ b/cmd/libsnap-confine-private/utils.c @@ -84,7 +84,8 @@ static int parse_bool(const char *text, bool * value, bool default_value) *value = default_value; return 0; } - for (int i = 0; i < sizeof sc_bool_names / sizeof *sc_bool_names; ++i) { + for (size_t i = 0; i < sizeof sc_bool_names / sizeof *sc_bool_names; + ++i) { if (strcmp(text, sc_bool_names[i].text) == 0) { *value = sc_bool_names[i].value; return 0; From 70d6c939c43d5c544064074d04040e32192da20a Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 07:56:20 +0100 Subject: [PATCH 05/14] libsnap-confine-private: reformat F() macro, include do-while braces Reformat the F() macro to make it readable. Make sure to include braces braces in do-while statement. Signed-off-by: Maciej Borzecki --- cmd/libsnap-confine-private/mount-opt.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/libsnap-confine-private/mount-opt.c b/cmd/libsnap-confine-private/mount-opt.c index fa3065df858..d035f49a088 100644 --- a/cmd/libsnap-confine-private/mount-opt.c +++ b/cmd/libsnap-confine-private/mount-opt.c @@ -33,7 +33,13 @@ const char *sc_mount_opt2str(char *buf, size_t buf_size, unsigned long flags) { unsigned long used = 0; sc_string_init(buf, buf_size); -#define F(FLAG, TEXT) do if (flags & (FLAG)) { sc_string_append(buf, buf_size, #TEXT ","); flags ^= (FLAG); } while (0) + +#define F(FLAG, TEXT) do { \ + if (flags & (FLAG)) { \ + sc_string_append(buf, buf_size, #TEXT ","); flags ^= (FLAG); \ + } \ + } while (0) + F(MS_RDONLY, ro); F(MS_NOSUID, nosuid); F(MS_NODEV, nodev); From fd8f5fb25641fb6891b1bd6c00de24137871066e Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 08:57:13 +0100 Subject: [PATCH 06/14] libsnap-confine-private: do not use nested functions Nested functions are not supported outside of gcc. Refactor the code using this feature. Signed-off-by: Maciej Borzecki --- .../cleanup-funcs-test.c | 13 +- cmd/libsnap-confine-private/mount-opt-test.c | 20 +- cmd/libsnap-confine-private/mount-opt.c | 33 +- cmd/libsnap-confine-private/mountinfo.c | 114 ++-- .../string-utils-test.c | 541 +++++++++--------- 5 files changed, 370 insertions(+), 351 deletions(-) diff --git a/cmd/libsnap-confine-private/cleanup-funcs-test.c b/cmd/libsnap-confine-private/cleanup-funcs-test.c index 7cc6cef1821..ca58ca4e8ba 100644 --- a/cmd/libsnap-confine-private/cleanup-funcs-test.c +++ b/cmd/libsnap-confine-private/cleanup-funcs-test.c @@ -20,15 +20,18 @@ #include +static int called = 0; + +void cleanup_fn(int *ptr) +{ + called = 1; +} + // Test that cleanup functions are applied as expected static void test_cleanup_sanity() { - int called = 0; - void fn(int *ptr) { - called = 1; - } { - int test SC_CLEANUP(fn); + int test SC_CLEANUP(cleanup_fn); test = 0; test++; } diff --git a/cmd/libsnap-confine-private/mount-opt-test.c b/cmd/libsnap-confine-private/mount-opt-test.c index 76fd6a52258..503950f326d 100644 --- a/cmd/libsnap-confine-private/mount-opt-test.c +++ b/cmd/libsnap-confine-private/mount-opt-test.c @@ -205,13 +205,15 @@ static void test_sc_umount_cmd(void) "umount --force --lazy --expire --no-follow /mnt/foo"); } +static bool broken_mount(struct sc_fault_state *state, void *ptr) +{ + errno = EACCES; + return true; +} + static void test_sc_do_mount(void) { if (g_test_subprocess()) { - bool broken_mount(struct sc_fault_state *state, void *ptr) { - errno = EACCES; - return true; - } sc_break("mount", broken_mount); sc_do_mount("/foo", "/bar", "ext4", MS_RDONLY, NULL); @@ -226,13 +228,15 @@ static void test_sc_do_mount(void) ("cannot perform operation: mount -t ext4 -o ro /foo /bar: Permission denied\n"); } +static bool broken_umount(struct sc_fault_state *state, void *ptr) +{ + errno = EACCES; + return true; +} + static void test_sc_do_umount(void) { if (g_test_subprocess()) { - bool broken_umount(struct sc_fault_state *state, void *ptr) { - errno = EACCES; - return true; - } sc_break("umount", broken_umount); sc_do_umount("/foo", MNT_DETACH); diff --git a/cmd/libsnap-confine-private/mount-opt.c b/cmd/libsnap-confine-private/mount-opt.c index d035f49a088..0e3f5a59d7d 100644 --- a/cmd/libsnap-confine-private/mount-opt.c +++ b/cmd/libsnap-confine-private/mount-opt.c @@ -258,17 +258,10 @@ void sc_do_mount(const char *source, const char *target, char buf[10000] = { 0 }; const char *mount_cmd = NULL; - void ensure_mount_cmd(void) { - if (mount_cmd != NULL) { - return; - } - mount_cmd = sc_mount_cmd(buf, sizeof buf, source, - target, fs_type, mountflags, data); - } - if (sc_is_debug_enabled()) { #ifdef SNAP_CONFINE_DEBUG_BUILD - ensure_mount_cmd(); + mount_cmd = sc_mount_cmd(buf, sizeof(buf), source, + target, fs_type, mountflags, data); #else mount_cmd = "(disabled) use debug build to see details"; #endif @@ -284,8 +277,11 @@ void sc_do_mount(const char *source, const char *target, sc_privs_drop(); // Compute the equivalent mount command. - ensure_mount_cmd(); - + if (mount_cmd == NULL) { + mount_cmd = sc_mount_cmd(buf, sizeof(buf), source, + target, fs_type, mountflags, + data); + } // Restore errno and die. errno = saved_errno; die("cannot perform operation: %s", mount_cmd); @@ -297,16 +293,9 @@ void sc_do_umount(const char *target, int flags) char buf[10000] = { 0 }; const char *umount_cmd = NULL; - void ensure_umount_cmd(void) { - if (umount_cmd != NULL) { - return; - } - umount_cmd = sc_umount_cmd(buf, sizeof buf, target, flags); - } - if (sc_is_debug_enabled()) { #ifdef SNAP_CONFINE_DEBUG_BUILD - ensure_umount_cmd(); + umount_cmd = sc_umount_cmd(buf, sizeof(buf), target, flags); #else umount_cmd = "(disabled) use debug build to see details"; #endif @@ -321,8 +310,10 @@ void sc_do_umount(const char *target, int flags) sc_privs_drop(); // Compute the equivalent umount command. - ensure_umount_cmd(); - + if (umount_cmd == NULL) { + umount_cmd = sc_umount_cmd(buf, sizeof(buf), + target, flags); + } // Restore errno and die. errno = saved_errno; die("cannot perform operation: %s", umount_cmd); diff --git a/cmd/libsnap-confine-private/mountinfo.c b/cmd/libsnap-confine-private/mountinfo.c index 5db3b309507..35a1e39d6d5 100644 --- a/cmd/libsnap-confine-private/mountinfo.c +++ b/cmd/libsnap-confine-private/mountinfo.c @@ -111,6 +111,50 @@ struct sc_mountinfo *sc_parse_mountinfo(const char *fname) return info; } +static void show_buffers(const char *line, int offset, + struct sc_mountinfo_entry *entry) +{ +#ifdef MOUNTINFO_DEBUG + fprintf(stderr, "Input buffer (first), with offset arrow\n"); + fprintf(stderr, "Output buffer (second)\n"); + + fputc(' ', stderr); + for (int i = 0; i < offset - 1; ++i) + fputc('-', stderr); + fputc('v', stderr); + fputc('\n', stderr); + + fprintf(stderr, ">%s<\n", line); + + fputc('>', stderr); + for (int i = 0; i < strlen(line); ++i) { + int c = entry->line_buf[i]; + fputc(c == 0 ? '@' : c == 1 ? '#' : c, stderr); + } + fputc('<', stderr); + fputc('\n', stderr); + + fputc('>', stderr); + for (int i = 0; i < strlen(line); ++i) + fputc('=', stderr); + fputc('<', stderr); + fputc('\n', stderr); +#endif // MOUNTINFO_DEBUG +} + +static char *parse_next_string_field(struct sc_mountinfo_entry *entry, + const char *line, int *offset, + int *offset_delta) +{ + char *field = &entry->line_buf[0] + *offset; + int nscanned = sscanf(line + *offset, "%s %n", field, offset_delta); + if (nscanned != 1) + return NULL; + *offset += *offset_delta; + show_buffers(line, *offset, entry); + return field; +} + static struct sc_mountinfo_entry *sc_parse_mountinfo_entry(const char *line) { // NOTE: the sc_mountinfo structure is allocated along with enough extra @@ -154,58 +198,26 @@ static struct sc_mountinfo_entry *sc_parse_mountinfo_entry(const char *line) goto fail; offset += offset_delta; - void show_buffers(void) { -#ifdef MOUNTINFO_DEBUG - fprintf(stderr, "Input buffer (first), with offset arrow\n"); - fprintf(stderr, "Output buffer (second)\n"); - - fputc(' ', stderr); - for (int i = 0; i < offset - 1; ++i) - fputc('-', stderr); - fputc('v', stderr); - fputc('\n', stderr); - - fprintf(stderr, ">%s<\n", line); - - fputc('>', stderr); - for (int i = 0; i < strlen(line); ++i) { - int c = entry->line_buf[i]; - fputc(c == 0 ? '@' : c == 1 ? '#' : c, stderr); - } - fputc('<', stderr); - fputc('\n', stderr); - - fputc('>', stderr); - for (int i = 0; i < strlen(line); ++i) - fputc('=', stderr); - fputc('<', stderr); - fputc('\n', stderr); -#endif // MOUNTINFO_DEBUG - } + show_buffers(line, offset, entry); - show_buffers(); - - char *parse_next_string_field(void) { - char *field = &entry->line_buf[0] + offset; - int nscanned = - sscanf(line + offset, "%s %n", field, &offset_delta); - if (nscanned != 1) - return NULL; - offset += offset_delta; - show_buffers(); - return field; - } - if ((entry->root = parse_next_string_field()) == NULL) + if ((entry->root = + parse_next_string_field(entry, line, &offset, + &offset_delta)) == NULL) goto fail; - if ((entry->mount_dir = parse_next_string_field()) == NULL) + if ((entry->mount_dir = + parse_next_string_field(entry, line, &offset, + &offset_delta)) == NULL) goto fail; - if ((entry->mount_opts = parse_next_string_field()) == NULL) + if ((entry->mount_opts = + parse_next_string_field(entry, line, &offset, + &offset_delta)) == NULL) goto fail; entry->optional_fields = &entry->line_buf[0] + offset; // NOTE: This ensures that optional_fields is never NULL. If this changes, // must adjust all callers of parse_mountinfo_entry() accordingly. for (int field_num = 0;; ++field_num) { - char *opt_field = parse_next_string_field(); + char *opt_field = parse_next_string_field(entry, line, &offset, + &offset_delta); if (opt_field == NULL) goto fail; if (strcmp(opt_field, "-") == 0) { @@ -216,13 +228,19 @@ static struct sc_mountinfo_entry *sc_parse_mountinfo_entry(const char *line) opt_field[-1] = ' '; } } - if ((entry->fs_type = parse_next_string_field()) == NULL) + if ((entry->fs_type = + parse_next_string_field(entry, line, &offset, + &offset_delta)) == NULL) goto fail; - if ((entry->mount_source = parse_next_string_field()) == NULL) + if ((entry->mount_source = + parse_next_string_field(entry, line, &offset, + &offset_delta)) == NULL) goto fail; - if ((entry->super_opts = parse_next_string_field()) == NULL) + if ((entry->super_opts = + parse_next_string_field(entry, line, &offset, + &offset_delta)) == NULL) goto fail; - show_buffers(); + show_buffers(line, offset, entry); return entry; fail: free(entry); diff --git a/cmd/libsnap-confine-private/string-utils-test.c b/cmd/libsnap-confine-private/string-utils-test.c index a2ee592ffe3..1d53662c343 100644 --- a/cmd/libsnap-confine-private/string-utils-test.c +++ b/cmd/libsnap-confine-private/string-utils-test.c @@ -448,302 +448,305 @@ static void test_sc_string_quote_NULL_str(void) g_test_trap_assert_stderr("cannot quote string: string is NULL\n"); } -static void test_sc_string_quote(void) +static void test_quoting_of(bool tested[], int c, const char *expected) { -#define DQ "\"" char buf[16]; - bool is_tested[256] = { false }; - void test_quoting_of(int c, const char *expected) { - g_assert_cmpint(c, >=, 0); - g_assert_cmpint(c, <=, 255); + g_assert_cmpint(c, >=, 0); + g_assert_cmpint(c, <=, 255); - // Create an input string with one character. - char input[2] = { (unsigned char)c, 0 }; - sc_string_quote(buf, sizeof buf, input); + // Create an input string with one character. + char input[2] = { (unsigned char)c, 0 }; + sc_string_quote(buf, sizeof buf, input); - // Ensure it was quoted as we expected. - g_assert_cmpstr(buf, ==, expected); + // Ensure it was quoted as we expected. + g_assert_cmpstr(buf, ==, expected); - is_tested[c] = true; - } + tested[c] = true; +} + +static void test_sc_string_quote(void) +{ +#define DQ "\"" + char buf[16]; + bool is_tested[256] = { false }; // Exhaustive test for quoting of every 8bit input. This is very verbose // but the goal is to have a very obvious and correct test that ensures no // edge case is lost. // // block 1: 0x00 - 0x0f - test_quoting_of(0x00, DQ "" DQ); - test_quoting_of(0x01, DQ "\\x01" DQ); - test_quoting_of(0x02, DQ "\\x02" DQ); - test_quoting_of(0x03, DQ "\\x03" DQ); - test_quoting_of(0x04, DQ "\\x04" DQ); - test_quoting_of(0x05, DQ "\\x05" DQ); - test_quoting_of(0x06, DQ "\\x06" DQ); - test_quoting_of(0x07, DQ "\\x07" DQ); - test_quoting_of(0x08, DQ "\\x08" DQ); - test_quoting_of(0x09, DQ "\\t" DQ); - test_quoting_of(0x0a, DQ "\\n" DQ); - test_quoting_of(0x0b, DQ "\\v" DQ); - test_quoting_of(0x0c, DQ "\\x0c" DQ); - test_quoting_of(0x0d, DQ "\\r" DQ); - test_quoting_of(0x0e, DQ "\\x0e" DQ); - test_quoting_of(0x0f, DQ "\\x0f" DQ); + test_quoting_of(is_tested, 0x00, DQ "" DQ); + test_quoting_of(is_tested, 0x01, DQ "\\x01" DQ); + test_quoting_of(is_tested, 0x02, DQ "\\x02" DQ); + test_quoting_of(is_tested, 0x03, DQ "\\x03" DQ); + test_quoting_of(is_tested, 0x04, DQ "\\x04" DQ); + test_quoting_of(is_tested, 0x05, DQ "\\x05" DQ); + test_quoting_of(is_tested, 0x06, DQ "\\x06" DQ); + test_quoting_of(is_tested, 0x07, DQ "\\x07" DQ); + test_quoting_of(is_tested, 0x08, DQ "\\x08" DQ); + test_quoting_of(is_tested, 0x09, DQ "\\t" DQ); + test_quoting_of(is_tested, 0x0a, DQ "\\n" DQ); + test_quoting_of(is_tested, 0x0b, DQ "\\v" DQ); + test_quoting_of(is_tested, 0x0c, DQ "\\x0c" DQ); + test_quoting_of(is_tested, 0x0d, DQ "\\r" DQ); + test_quoting_of(is_tested, 0x0e, DQ "\\x0e" DQ); + test_quoting_of(is_tested, 0x0f, DQ "\\x0f" DQ); // block 2: 0x10 - 0x1f - test_quoting_of(0x10, DQ "\\x10" DQ); - test_quoting_of(0x11, DQ "\\x11" DQ); - test_quoting_of(0x12, DQ "\\x12" DQ); - test_quoting_of(0x13, DQ "\\x13" DQ); - test_quoting_of(0x14, DQ "\\x14" DQ); - test_quoting_of(0x15, DQ "\\x15" DQ); - test_quoting_of(0x16, DQ "\\x16" DQ); - test_quoting_of(0x17, DQ "\\x17" DQ); - test_quoting_of(0x18, DQ "\\x18" DQ); - test_quoting_of(0x19, DQ "\\x19" DQ); - test_quoting_of(0x1a, DQ "\\x1a" DQ); - test_quoting_of(0x1b, DQ "\\x1b" DQ); - test_quoting_of(0x1c, DQ "\\x1c" DQ); - test_quoting_of(0x1d, DQ "\\x1d" DQ); - test_quoting_of(0x1e, DQ "\\x1e" DQ); - test_quoting_of(0x1f, DQ "\\x1f" DQ); + test_quoting_of(is_tested, 0x10, DQ "\\x10" DQ); + test_quoting_of(is_tested, 0x11, DQ "\\x11" DQ); + test_quoting_of(is_tested, 0x12, DQ "\\x12" DQ); + test_quoting_of(is_tested, 0x13, DQ "\\x13" DQ); + test_quoting_of(is_tested, 0x14, DQ "\\x14" DQ); + test_quoting_of(is_tested, 0x15, DQ "\\x15" DQ); + test_quoting_of(is_tested, 0x16, DQ "\\x16" DQ); + test_quoting_of(is_tested, 0x17, DQ "\\x17" DQ); + test_quoting_of(is_tested, 0x18, DQ "\\x18" DQ); + test_quoting_of(is_tested, 0x19, DQ "\\x19" DQ); + test_quoting_of(is_tested, 0x1a, DQ "\\x1a" DQ); + test_quoting_of(is_tested, 0x1b, DQ "\\x1b" DQ); + test_quoting_of(is_tested, 0x1c, DQ "\\x1c" DQ); + test_quoting_of(is_tested, 0x1d, DQ "\\x1d" DQ); + test_quoting_of(is_tested, 0x1e, DQ "\\x1e" DQ); + test_quoting_of(is_tested, 0x1f, DQ "\\x1f" DQ); // block 3: 0x20 - 0x2f - test_quoting_of(0x20, DQ " " DQ); - test_quoting_of(0x21, DQ "!" DQ); - test_quoting_of(0x22, DQ "\\\"" DQ); - test_quoting_of(0x23, DQ "#" DQ); - test_quoting_of(0x24, DQ "$" DQ); - test_quoting_of(0x25, DQ "%" DQ); - test_quoting_of(0x26, DQ "&" DQ); - test_quoting_of(0x27, DQ "'" DQ); - test_quoting_of(0x28, DQ "(" DQ); - test_quoting_of(0x29, DQ ")" DQ); - test_quoting_of(0x2a, DQ "*" DQ); - test_quoting_of(0x2b, DQ "+" DQ); - test_quoting_of(0x2c, DQ "," DQ); - test_quoting_of(0x2d, DQ "-" DQ); - test_quoting_of(0x2e, DQ "." DQ); - test_quoting_of(0x2f, DQ "/" DQ); + test_quoting_of(is_tested, 0x20, DQ " " DQ); + test_quoting_of(is_tested, 0x21, DQ "!" DQ); + test_quoting_of(is_tested, 0x22, DQ "\\\"" DQ); + test_quoting_of(is_tested, 0x23, DQ "#" DQ); + test_quoting_of(is_tested, 0x24, DQ "$" DQ); + test_quoting_of(is_tested, 0x25, DQ "%" DQ); + test_quoting_of(is_tested, 0x26, DQ "&" DQ); + test_quoting_of(is_tested, 0x27, DQ "'" DQ); + test_quoting_of(is_tested, 0x28, DQ "(" DQ); + test_quoting_of(is_tested, 0x29, DQ ")" DQ); + test_quoting_of(is_tested, 0x2a, DQ "*" DQ); + test_quoting_of(is_tested, 0x2b, DQ "+" DQ); + test_quoting_of(is_tested, 0x2c, DQ "," DQ); + test_quoting_of(is_tested, 0x2d, DQ "-" DQ); + test_quoting_of(is_tested, 0x2e, DQ "." DQ); + test_quoting_of(is_tested, 0x2f, DQ "/" DQ); // block 4: 0x30 - 0x3f - test_quoting_of(0x30, DQ "0" DQ); - test_quoting_of(0x31, DQ "1" DQ); - test_quoting_of(0x32, DQ "2" DQ); - test_quoting_of(0x33, DQ "3" DQ); - test_quoting_of(0x34, DQ "4" DQ); - test_quoting_of(0x35, DQ "5" DQ); - test_quoting_of(0x36, DQ "6" DQ); - test_quoting_of(0x37, DQ "7" DQ); - test_quoting_of(0x38, DQ "8" DQ); - test_quoting_of(0x39, DQ "9" DQ); - test_quoting_of(0x3a, DQ ":" DQ); - test_quoting_of(0x3b, DQ ";" DQ); - test_quoting_of(0x3c, DQ "<" DQ); - test_quoting_of(0x3d, DQ "=" DQ); - test_quoting_of(0x3e, DQ ">" DQ); - test_quoting_of(0x3f, DQ "?" DQ); + test_quoting_of(is_tested, 0x30, DQ "0" DQ); + test_quoting_of(is_tested, 0x31, DQ "1" DQ); + test_quoting_of(is_tested, 0x32, DQ "2" DQ); + test_quoting_of(is_tested, 0x33, DQ "3" DQ); + test_quoting_of(is_tested, 0x34, DQ "4" DQ); + test_quoting_of(is_tested, 0x35, DQ "5" DQ); + test_quoting_of(is_tested, 0x36, DQ "6" DQ); + test_quoting_of(is_tested, 0x37, DQ "7" DQ); + test_quoting_of(is_tested, 0x38, DQ "8" DQ); + test_quoting_of(is_tested, 0x39, DQ "9" DQ); + test_quoting_of(is_tested, 0x3a, DQ ":" DQ); + test_quoting_of(is_tested, 0x3b, DQ ";" DQ); + test_quoting_of(is_tested, 0x3c, DQ "<" DQ); + test_quoting_of(is_tested, 0x3d, DQ "=" DQ); + test_quoting_of(is_tested, 0x3e, DQ ">" DQ); + test_quoting_of(is_tested, 0x3f, DQ "?" DQ); // block 5: 0x40 - 0x4f - test_quoting_of(0x40, DQ "@" DQ); - test_quoting_of(0x41, DQ "A" DQ); - test_quoting_of(0x42, DQ "B" DQ); - test_quoting_of(0x43, DQ "C" DQ); - test_quoting_of(0x44, DQ "D" DQ); - test_quoting_of(0x45, DQ "E" DQ); - test_quoting_of(0x46, DQ "F" DQ); - test_quoting_of(0x47, DQ "G" DQ); - test_quoting_of(0x48, DQ "H" DQ); - test_quoting_of(0x49, DQ "I" DQ); - test_quoting_of(0x4a, DQ "J" DQ); - test_quoting_of(0x4b, DQ "K" DQ); - test_quoting_of(0x4c, DQ "L" DQ); - test_quoting_of(0x4d, DQ "M" DQ); - test_quoting_of(0x4e, DQ "N" DQ); - test_quoting_of(0x4f, DQ "O" DQ); + test_quoting_of(is_tested, 0x40, DQ "@" DQ); + test_quoting_of(is_tested, 0x41, DQ "A" DQ); + test_quoting_of(is_tested, 0x42, DQ "B" DQ); + test_quoting_of(is_tested, 0x43, DQ "C" DQ); + test_quoting_of(is_tested, 0x44, DQ "D" DQ); + test_quoting_of(is_tested, 0x45, DQ "E" DQ); + test_quoting_of(is_tested, 0x46, DQ "F" DQ); + test_quoting_of(is_tested, 0x47, DQ "G" DQ); + test_quoting_of(is_tested, 0x48, DQ "H" DQ); + test_quoting_of(is_tested, 0x49, DQ "I" DQ); + test_quoting_of(is_tested, 0x4a, DQ "J" DQ); + test_quoting_of(is_tested, 0x4b, DQ "K" DQ); + test_quoting_of(is_tested, 0x4c, DQ "L" DQ); + test_quoting_of(is_tested, 0x4d, DQ "M" DQ); + test_quoting_of(is_tested, 0x4e, DQ "N" DQ); + test_quoting_of(is_tested, 0x4f, DQ "O" DQ); // block 6: 0x50 - 0x5f - test_quoting_of(0x50, DQ "P" DQ); - test_quoting_of(0x51, DQ "Q" DQ); - test_quoting_of(0x52, DQ "R" DQ); - test_quoting_of(0x53, DQ "S" DQ); - test_quoting_of(0x54, DQ "T" DQ); - test_quoting_of(0x55, DQ "U" DQ); - test_quoting_of(0x56, DQ "V" DQ); - test_quoting_of(0x57, DQ "W" DQ); - test_quoting_of(0x58, DQ "X" DQ); - test_quoting_of(0x59, DQ "Y" DQ); - test_quoting_of(0x5a, DQ "Z" DQ); - test_quoting_of(0x5b, DQ "[" DQ); - test_quoting_of(0x5c, DQ "\\\\" DQ); - test_quoting_of(0x5d, DQ "]" DQ); - test_quoting_of(0x5e, DQ "^" DQ); - test_quoting_of(0x5f, DQ "_" DQ); + test_quoting_of(is_tested, 0x50, DQ "P" DQ); + test_quoting_of(is_tested, 0x51, DQ "Q" DQ); + test_quoting_of(is_tested, 0x52, DQ "R" DQ); + test_quoting_of(is_tested, 0x53, DQ "S" DQ); + test_quoting_of(is_tested, 0x54, DQ "T" DQ); + test_quoting_of(is_tested, 0x55, DQ "U" DQ); + test_quoting_of(is_tested, 0x56, DQ "V" DQ); + test_quoting_of(is_tested, 0x57, DQ "W" DQ); + test_quoting_of(is_tested, 0x58, DQ "X" DQ); + test_quoting_of(is_tested, 0x59, DQ "Y" DQ); + test_quoting_of(is_tested, 0x5a, DQ "Z" DQ); + test_quoting_of(is_tested, 0x5b, DQ "[" DQ); + test_quoting_of(is_tested, 0x5c, DQ "\\\\" DQ); + test_quoting_of(is_tested, 0x5d, DQ "]" DQ); + test_quoting_of(is_tested, 0x5e, DQ "^" DQ); + test_quoting_of(is_tested, 0x5f, DQ "_" DQ); // block 7: 0x60 - 0x6f - test_quoting_of(0x60, DQ "`" DQ); - test_quoting_of(0x61, DQ "a" DQ); - test_quoting_of(0x62, DQ "b" DQ); - test_quoting_of(0x63, DQ "c" DQ); - test_quoting_of(0x64, DQ "d" DQ); - test_quoting_of(0x65, DQ "e" DQ); - test_quoting_of(0x66, DQ "f" DQ); - test_quoting_of(0x67, DQ "g" DQ); - test_quoting_of(0x68, DQ "h" DQ); - test_quoting_of(0x69, DQ "i" DQ); - test_quoting_of(0x6a, DQ "j" DQ); - test_quoting_of(0x6b, DQ "k" DQ); - test_quoting_of(0x6c, DQ "l" DQ); - test_quoting_of(0x6d, DQ "m" DQ); - test_quoting_of(0x6e, DQ "n" DQ); - test_quoting_of(0x6f, DQ "o" DQ); + test_quoting_of(is_tested, 0x60, DQ "`" DQ); + test_quoting_of(is_tested, 0x61, DQ "a" DQ); + test_quoting_of(is_tested, 0x62, DQ "b" DQ); + test_quoting_of(is_tested, 0x63, DQ "c" DQ); + test_quoting_of(is_tested, 0x64, DQ "d" DQ); + test_quoting_of(is_tested, 0x65, DQ "e" DQ); + test_quoting_of(is_tested, 0x66, DQ "f" DQ); + test_quoting_of(is_tested, 0x67, DQ "g" DQ); + test_quoting_of(is_tested, 0x68, DQ "h" DQ); + test_quoting_of(is_tested, 0x69, DQ "i" DQ); + test_quoting_of(is_tested, 0x6a, DQ "j" DQ); + test_quoting_of(is_tested, 0x6b, DQ "k" DQ); + test_quoting_of(is_tested, 0x6c, DQ "l" DQ); + test_quoting_of(is_tested, 0x6d, DQ "m" DQ); + test_quoting_of(is_tested, 0x6e, DQ "n" DQ); + test_quoting_of(is_tested, 0x6f, DQ "o" DQ); // block 8: 0x70 - 0x7f - test_quoting_of(0x70, DQ "p" DQ); - test_quoting_of(0x71, DQ "q" DQ); - test_quoting_of(0x72, DQ "r" DQ); - test_quoting_of(0x73, DQ "s" DQ); - test_quoting_of(0x74, DQ "t" DQ); - test_quoting_of(0x75, DQ "u" DQ); - test_quoting_of(0x76, DQ "v" DQ); - test_quoting_of(0x77, DQ "w" DQ); - test_quoting_of(0x78, DQ "x" DQ); - test_quoting_of(0x79, DQ "y" DQ); - test_quoting_of(0x7a, DQ "z" DQ); - test_quoting_of(0x7b, DQ "{" DQ); - test_quoting_of(0x7c, DQ "|" DQ); - test_quoting_of(0x7d, DQ "}" DQ); - test_quoting_of(0x7e, DQ "~" DQ); - test_quoting_of(0x7f, DQ "\\x7f" DQ); + test_quoting_of(is_tested, 0x70, DQ "p" DQ); + test_quoting_of(is_tested, 0x71, DQ "q" DQ); + test_quoting_of(is_tested, 0x72, DQ "r" DQ); + test_quoting_of(is_tested, 0x73, DQ "s" DQ); + test_quoting_of(is_tested, 0x74, DQ "t" DQ); + test_quoting_of(is_tested, 0x75, DQ "u" DQ); + test_quoting_of(is_tested, 0x76, DQ "v" DQ); + test_quoting_of(is_tested, 0x77, DQ "w" DQ); + test_quoting_of(is_tested, 0x78, DQ "x" DQ); + test_quoting_of(is_tested, 0x79, DQ "y" DQ); + test_quoting_of(is_tested, 0x7a, DQ "z" DQ); + test_quoting_of(is_tested, 0x7b, DQ "{" DQ); + test_quoting_of(is_tested, 0x7c, DQ "|" DQ); + test_quoting_of(is_tested, 0x7d, DQ "}" DQ); + test_quoting_of(is_tested, 0x7e, DQ "~" DQ); + test_quoting_of(is_tested, 0x7f, DQ "\\x7f" DQ); // block 9 (8-bit): 0x80 - 0x8f - test_quoting_of(0x80, DQ "\\x80" DQ); - test_quoting_of(0x81, DQ "\\x81" DQ); - test_quoting_of(0x82, DQ "\\x82" DQ); - test_quoting_of(0x83, DQ "\\x83" DQ); - test_quoting_of(0x84, DQ "\\x84" DQ); - test_quoting_of(0x85, DQ "\\x85" DQ); - test_quoting_of(0x86, DQ "\\x86" DQ); - test_quoting_of(0x87, DQ "\\x87" DQ); - test_quoting_of(0x88, DQ "\\x88" DQ); - test_quoting_of(0x89, DQ "\\x89" DQ); - test_quoting_of(0x8a, DQ "\\x8a" DQ); - test_quoting_of(0x8b, DQ "\\x8b" DQ); - test_quoting_of(0x8c, DQ "\\x8c" DQ); - test_quoting_of(0x8d, DQ "\\x8d" DQ); - test_quoting_of(0x8e, DQ "\\x8e" DQ); - test_quoting_of(0x8f, DQ "\\x8f" DQ); + test_quoting_of(is_tested, 0x80, DQ "\\x80" DQ); + test_quoting_of(is_tested, 0x81, DQ "\\x81" DQ); + test_quoting_of(is_tested, 0x82, DQ "\\x82" DQ); + test_quoting_of(is_tested, 0x83, DQ "\\x83" DQ); + test_quoting_of(is_tested, 0x84, DQ "\\x84" DQ); + test_quoting_of(is_tested, 0x85, DQ "\\x85" DQ); + test_quoting_of(is_tested, 0x86, DQ "\\x86" DQ); + test_quoting_of(is_tested, 0x87, DQ "\\x87" DQ); + test_quoting_of(is_tested, 0x88, DQ "\\x88" DQ); + test_quoting_of(is_tested, 0x89, DQ "\\x89" DQ); + test_quoting_of(is_tested, 0x8a, DQ "\\x8a" DQ); + test_quoting_of(is_tested, 0x8b, DQ "\\x8b" DQ); + test_quoting_of(is_tested, 0x8c, DQ "\\x8c" DQ); + test_quoting_of(is_tested, 0x8d, DQ "\\x8d" DQ); + test_quoting_of(is_tested, 0x8e, DQ "\\x8e" DQ); + test_quoting_of(is_tested, 0x8f, DQ "\\x8f" DQ); // block 10 (8-bit): 0x90 - 0x9f - test_quoting_of(0x90, DQ "\\x90" DQ); - test_quoting_of(0x91, DQ "\\x91" DQ); - test_quoting_of(0x92, DQ "\\x92" DQ); - test_quoting_of(0x93, DQ "\\x93" DQ); - test_quoting_of(0x94, DQ "\\x94" DQ); - test_quoting_of(0x95, DQ "\\x95" DQ); - test_quoting_of(0x96, DQ "\\x96" DQ); - test_quoting_of(0x97, DQ "\\x97" DQ); - test_quoting_of(0x98, DQ "\\x98" DQ); - test_quoting_of(0x99, DQ "\\x99" DQ); - test_quoting_of(0x9a, DQ "\\x9a" DQ); - test_quoting_of(0x9b, DQ "\\x9b" DQ); - test_quoting_of(0x9c, DQ "\\x9c" DQ); - test_quoting_of(0x9d, DQ "\\x9d" DQ); - test_quoting_of(0x9e, DQ "\\x9e" DQ); - test_quoting_of(0x9f, DQ "\\x9f" DQ); + test_quoting_of(is_tested, 0x90, DQ "\\x90" DQ); + test_quoting_of(is_tested, 0x91, DQ "\\x91" DQ); + test_quoting_of(is_tested, 0x92, DQ "\\x92" DQ); + test_quoting_of(is_tested, 0x93, DQ "\\x93" DQ); + test_quoting_of(is_tested, 0x94, DQ "\\x94" DQ); + test_quoting_of(is_tested, 0x95, DQ "\\x95" DQ); + test_quoting_of(is_tested, 0x96, DQ "\\x96" DQ); + test_quoting_of(is_tested, 0x97, DQ "\\x97" DQ); + test_quoting_of(is_tested, 0x98, DQ "\\x98" DQ); + test_quoting_of(is_tested, 0x99, DQ "\\x99" DQ); + test_quoting_of(is_tested, 0x9a, DQ "\\x9a" DQ); + test_quoting_of(is_tested, 0x9b, DQ "\\x9b" DQ); + test_quoting_of(is_tested, 0x9c, DQ "\\x9c" DQ); + test_quoting_of(is_tested, 0x9d, DQ "\\x9d" DQ); + test_quoting_of(is_tested, 0x9e, DQ "\\x9e" DQ); + test_quoting_of(is_tested, 0x9f, DQ "\\x9f" DQ); // block 11 (8-bit): 0xa0 - 0xaf - test_quoting_of(0xa0, DQ "\\xa0" DQ); - test_quoting_of(0xa1, DQ "\\xa1" DQ); - test_quoting_of(0xa2, DQ "\\xa2" DQ); - test_quoting_of(0xa3, DQ "\\xa3" DQ); - test_quoting_of(0xa4, DQ "\\xa4" DQ); - test_quoting_of(0xa5, DQ "\\xa5" DQ); - test_quoting_of(0xa6, DQ "\\xa6" DQ); - test_quoting_of(0xa7, DQ "\\xa7" DQ); - test_quoting_of(0xa8, DQ "\\xa8" DQ); - test_quoting_of(0xa9, DQ "\\xa9" DQ); - test_quoting_of(0xaa, DQ "\\xaa" DQ); - test_quoting_of(0xab, DQ "\\xab" DQ); - test_quoting_of(0xac, DQ "\\xac" DQ); - test_quoting_of(0xad, DQ "\\xad" DQ); - test_quoting_of(0xae, DQ "\\xae" DQ); - test_quoting_of(0xaf, DQ "\\xaf" DQ); + test_quoting_of(is_tested, 0xa0, DQ "\\xa0" DQ); + test_quoting_of(is_tested, 0xa1, DQ "\\xa1" DQ); + test_quoting_of(is_tested, 0xa2, DQ "\\xa2" DQ); + test_quoting_of(is_tested, 0xa3, DQ "\\xa3" DQ); + test_quoting_of(is_tested, 0xa4, DQ "\\xa4" DQ); + test_quoting_of(is_tested, 0xa5, DQ "\\xa5" DQ); + test_quoting_of(is_tested, 0xa6, DQ "\\xa6" DQ); + test_quoting_of(is_tested, 0xa7, DQ "\\xa7" DQ); + test_quoting_of(is_tested, 0xa8, DQ "\\xa8" DQ); + test_quoting_of(is_tested, 0xa9, DQ "\\xa9" DQ); + test_quoting_of(is_tested, 0xaa, DQ "\\xaa" DQ); + test_quoting_of(is_tested, 0xab, DQ "\\xab" DQ); + test_quoting_of(is_tested, 0xac, DQ "\\xac" DQ); + test_quoting_of(is_tested, 0xad, DQ "\\xad" DQ); + test_quoting_of(is_tested, 0xae, DQ "\\xae" DQ); + test_quoting_of(is_tested, 0xaf, DQ "\\xaf" DQ); // block 12 (8-bit): 0xb0 - 0xbf - test_quoting_of(0xb0, DQ "\\xb0" DQ); - test_quoting_of(0xb1, DQ "\\xb1" DQ); - test_quoting_of(0xb2, DQ "\\xb2" DQ); - test_quoting_of(0xb3, DQ "\\xb3" DQ); - test_quoting_of(0xb4, DQ "\\xb4" DQ); - test_quoting_of(0xb5, DQ "\\xb5" DQ); - test_quoting_of(0xb6, DQ "\\xb6" DQ); - test_quoting_of(0xb7, DQ "\\xb7" DQ); - test_quoting_of(0xb8, DQ "\\xb8" DQ); - test_quoting_of(0xb9, DQ "\\xb9" DQ); - test_quoting_of(0xba, DQ "\\xba" DQ); - test_quoting_of(0xbb, DQ "\\xbb" DQ); - test_quoting_of(0xbc, DQ "\\xbc" DQ); - test_quoting_of(0xbd, DQ "\\xbd" DQ); - test_quoting_of(0xbe, DQ "\\xbe" DQ); - test_quoting_of(0xbf, DQ "\\xbf" DQ); + test_quoting_of(is_tested, 0xb0, DQ "\\xb0" DQ); + test_quoting_of(is_tested, 0xb1, DQ "\\xb1" DQ); + test_quoting_of(is_tested, 0xb2, DQ "\\xb2" DQ); + test_quoting_of(is_tested, 0xb3, DQ "\\xb3" DQ); + test_quoting_of(is_tested, 0xb4, DQ "\\xb4" DQ); + test_quoting_of(is_tested, 0xb5, DQ "\\xb5" DQ); + test_quoting_of(is_tested, 0xb6, DQ "\\xb6" DQ); + test_quoting_of(is_tested, 0xb7, DQ "\\xb7" DQ); + test_quoting_of(is_tested, 0xb8, DQ "\\xb8" DQ); + test_quoting_of(is_tested, 0xb9, DQ "\\xb9" DQ); + test_quoting_of(is_tested, 0xba, DQ "\\xba" DQ); + test_quoting_of(is_tested, 0xbb, DQ "\\xbb" DQ); + test_quoting_of(is_tested, 0xbc, DQ "\\xbc" DQ); + test_quoting_of(is_tested, 0xbd, DQ "\\xbd" DQ); + test_quoting_of(is_tested, 0xbe, DQ "\\xbe" DQ); + test_quoting_of(is_tested, 0xbf, DQ "\\xbf" DQ); // block 13 (8-bit): 0xc0 - 0xcf - test_quoting_of(0xc0, DQ "\\xc0" DQ); - test_quoting_of(0xc1, DQ "\\xc1" DQ); - test_quoting_of(0xc2, DQ "\\xc2" DQ); - test_quoting_of(0xc3, DQ "\\xc3" DQ); - test_quoting_of(0xc4, DQ "\\xc4" DQ); - test_quoting_of(0xc5, DQ "\\xc5" DQ); - test_quoting_of(0xc6, DQ "\\xc6" DQ); - test_quoting_of(0xc7, DQ "\\xc7" DQ); - test_quoting_of(0xc8, DQ "\\xc8" DQ); - test_quoting_of(0xc9, DQ "\\xc9" DQ); - test_quoting_of(0xca, DQ "\\xca" DQ); - test_quoting_of(0xcb, DQ "\\xcb" DQ); - test_quoting_of(0xcc, DQ "\\xcc" DQ); - test_quoting_of(0xcd, DQ "\\xcd" DQ); - test_quoting_of(0xce, DQ "\\xce" DQ); - test_quoting_of(0xcf, DQ "\\xcf" DQ); + test_quoting_of(is_tested, 0xc0, DQ "\\xc0" DQ); + test_quoting_of(is_tested, 0xc1, DQ "\\xc1" DQ); + test_quoting_of(is_tested, 0xc2, DQ "\\xc2" DQ); + test_quoting_of(is_tested, 0xc3, DQ "\\xc3" DQ); + test_quoting_of(is_tested, 0xc4, DQ "\\xc4" DQ); + test_quoting_of(is_tested, 0xc5, DQ "\\xc5" DQ); + test_quoting_of(is_tested, 0xc6, DQ "\\xc6" DQ); + test_quoting_of(is_tested, 0xc7, DQ "\\xc7" DQ); + test_quoting_of(is_tested, 0xc8, DQ "\\xc8" DQ); + test_quoting_of(is_tested, 0xc9, DQ "\\xc9" DQ); + test_quoting_of(is_tested, 0xca, DQ "\\xca" DQ); + test_quoting_of(is_tested, 0xcb, DQ "\\xcb" DQ); + test_quoting_of(is_tested, 0xcc, DQ "\\xcc" DQ); + test_quoting_of(is_tested, 0xcd, DQ "\\xcd" DQ); + test_quoting_of(is_tested, 0xce, DQ "\\xce" DQ); + test_quoting_of(is_tested, 0xcf, DQ "\\xcf" DQ); // block 14 (8-bit): 0xd0 - 0xdf - test_quoting_of(0xd0, DQ "\\xd0" DQ); - test_quoting_of(0xd1, DQ "\\xd1" DQ); - test_quoting_of(0xd2, DQ "\\xd2" DQ); - test_quoting_of(0xd3, DQ "\\xd3" DQ); - test_quoting_of(0xd4, DQ "\\xd4" DQ); - test_quoting_of(0xd5, DQ "\\xd5" DQ); - test_quoting_of(0xd6, DQ "\\xd6" DQ); - test_quoting_of(0xd7, DQ "\\xd7" DQ); - test_quoting_of(0xd8, DQ "\\xd8" DQ); - test_quoting_of(0xd9, DQ "\\xd9" DQ); - test_quoting_of(0xda, DQ "\\xda" DQ); - test_quoting_of(0xdb, DQ "\\xdb" DQ); - test_quoting_of(0xdc, DQ "\\xdc" DQ); - test_quoting_of(0xdd, DQ "\\xdd" DQ); - test_quoting_of(0xde, DQ "\\xde" DQ); - test_quoting_of(0xdf, DQ "\\xdf" DQ); + test_quoting_of(is_tested, 0xd0, DQ "\\xd0" DQ); + test_quoting_of(is_tested, 0xd1, DQ "\\xd1" DQ); + test_quoting_of(is_tested, 0xd2, DQ "\\xd2" DQ); + test_quoting_of(is_tested, 0xd3, DQ "\\xd3" DQ); + test_quoting_of(is_tested, 0xd4, DQ "\\xd4" DQ); + test_quoting_of(is_tested, 0xd5, DQ "\\xd5" DQ); + test_quoting_of(is_tested, 0xd6, DQ "\\xd6" DQ); + test_quoting_of(is_tested, 0xd7, DQ "\\xd7" DQ); + test_quoting_of(is_tested, 0xd8, DQ "\\xd8" DQ); + test_quoting_of(is_tested, 0xd9, DQ "\\xd9" DQ); + test_quoting_of(is_tested, 0xda, DQ "\\xda" DQ); + test_quoting_of(is_tested, 0xdb, DQ "\\xdb" DQ); + test_quoting_of(is_tested, 0xdc, DQ "\\xdc" DQ); + test_quoting_of(is_tested, 0xdd, DQ "\\xdd" DQ); + test_quoting_of(is_tested, 0xde, DQ "\\xde" DQ); + test_quoting_of(is_tested, 0xdf, DQ "\\xdf" DQ); // block 15 (8-bit): 0xe0 - 0xef - test_quoting_of(0xe0, DQ "\\xe0" DQ); - test_quoting_of(0xe1, DQ "\\xe1" DQ); - test_quoting_of(0xe2, DQ "\\xe2" DQ); - test_quoting_of(0xe3, DQ "\\xe3" DQ); - test_quoting_of(0xe4, DQ "\\xe4" DQ); - test_quoting_of(0xe5, DQ "\\xe5" DQ); - test_quoting_of(0xe6, DQ "\\xe6" DQ); - test_quoting_of(0xe7, DQ "\\xe7" DQ); - test_quoting_of(0xe8, DQ "\\xe8" DQ); - test_quoting_of(0xe9, DQ "\\xe9" DQ); - test_quoting_of(0xea, DQ "\\xea" DQ); - test_quoting_of(0xeb, DQ "\\xeb" DQ); - test_quoting_of(0xec, DQ "\\xec" DQ); - test_quoting_of(0xed, DQ "\\xed" DQ); - test_quoting_of(0xee, DQ "\\xee" DQ); - test_quoting_of(0xef, DQ "\\xef" DQ); + test_quoting_of(is_tested, 0xe0, DQ "\\xe0" DQ); + test_quoting_of(is_tested, 0xe1, DQ "\\xe1" DQ); + test_quoting_of(is_tested, 0xe2, DQ "\\xe2" DQ); + test_quoting_of(is_tested, 0xe3, DQ "\\xe3" DQ); + test_quoting_of(is_tested, 0xe4, DQ "\\xe4" DQ); + test_quoting_of(is_tested, 0xe5, DQ "\\xe5" DQ); + test_quoting_of(is_tested, 0xe6, DQ "\\xe6" DQ); + test_quoting_of(is_tested, 0xe7, DQ "\\xe7" DQ); + test_quoting_of(is_tested, 0xe8, DQ "\\xe8" DQ); + test_quoting_of(is_tested, 0xe9, DQ "\\xe9" DQ); + test_quoting_of(is_tested, 0xea, DQ "\\xea" DQ); + test_quoting_of(is_tested, 0xeb, DQ "\\xeb" DQ); + test_quoting_of(is_tested, 0xec, DQ "\\xec" DQ); + test_quoting_of(is_tested, 0xed, DQ "\\xed" DQ); + test_quoting_of(is_tested, 0xee, DQ "\\xee" DQ); + test_quoting_of(is_tested, 0xef, DQ "\\xef" DQ); // block 16 (8-bit): 0xf0 - 0xff - test_quoting_of(0xf0, DQ "\\xf0" DQ); - test_quoting_of(0xf1, DQ "\\xf1" DQ); - test_quoting_of(0xf2, DQ "\\xf2" DQ); - test_quoting_of(0xf3, DQ "\\xf3" DQ); - test_quoting_of(0xf4, DQ "\\xf4" DQ); - test_quoting_of(0xf5, DQ "\\xf5" DQ); - test_quoting_of(0xf6, DQ "\\xf6" DQ); - test_quoting_of(0xf7, DQ "\\xf7" DQ); - test_quoting_of(0xf8, DQ "\\xf8" DQ); - test_quoting_of(0xf9, DQ "\\xf9" DQ); - test_quoting_of(0xfa, DQ "\\xfa" DQ); - test_quoting_of(0xfb, DQ "\\xfb" DQ); - test_quoting_of(0xfc, DQ "\\xfc" DQ); - test_quoting_of(0xfd, DQ "\\xfd" DQ); - test_quoting_of(0xfe, DQ "\\xfe" DQ); - test_quoting_of(0xff, DQ "\\xff" DQ); + test_quoting_of(is_tested, 0xf0, DQ "\\xf0" DQ); + test_quoting_of(is_tested, 0xf1, DQ "\\xf1" DQ); + test_quoting_of(is_tested, 0xf2, DQ "\\xf2" DQ); + test_quoting_of(is_tested, 0xf3, DQ "\\xf3" DQ); + test_quoting_of(is_tested, 0xf4, DQ "\\xf4" DQ); + test_quoting_of(is_tested, 0xf5, DQ "\\xf5" DQ); + test_quoting_of(is_tested, 0xf6, DQ "\\xf6" DQ); + test_quoting_of(is_tested, 0xf7, DQ "\\xf7" DQ); + test_quoting_of(is_tested, 0xf8, DQ "\\xf8" DQ); + test_quoting_of(is_tested, 0xf9, DQ "\\xf9" DQ); + test_quoting_of(is_tested, 0xfa, DQ "\\xfa" DQ); + test_quoting_of(is_tested, 0xfb, DQ "\\xfb" DQ); + test_quoting_of(is_tested, 0xfc, DQ "\\xfc" DQ); + test_quoting_of(is_tested, 0xfd, DQ "\\xfd" DQ); + test_quoting_of(is_tested, 0xfe, DQ "\\xfe" DQ); + test_quoting_of(is_tested, 0xff, DQ "\\xff" DQ); // Ensure the search was exhaustive. for (int i = 0; i <= 0xff; ++i) { From 706a213bcec1851577d367b74b4a1a5beab7c757 Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 12:35:19 +0100 Subject: [PATCH 07/14] tests/unit/c-unit-tests: rename to unit-tests-gcc to indicate that tests are gcc specific Rename the test to indicate that it is GCC specific Signed-off-by: Maciej Borzecki --- tests/unit/{c-unit-tests => c-unit-tests-gcc}/task.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename tests/unit/{c-unit-tests => c-unit-tests-gcc}/task.yaml (96%) diff --git a/tests/unit/c-unit-tests/task.yaml b/tests/unit/c-unit-tests-gcc/task.yaml similarity index 96% rename from tests/unit/c-unit-tests/task.yaml rename to tests/unit/c-unit-tests-gcc/task.yaml index 136088d01dd..be511c2ba7d 100644 --- a/tests/unit/c-unit-tests/task.yaml +++ b/tests/unit/c-unit-tests-gcc/task.yaml @@ -1,4 +1,4 @@ -summary: Run the test suite for C code +summary: Build the test suite for C code using gcc and run it prepare: | # Sanity check, the core snap is installed snap info core | MATCH "installed:" From 597029b02e5be568115ca28479060d6728adfd18 Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 12:36:59 +0100 Subject: [PATCH 08/14] tests/unit/c-unit-tests-clang: unit tests of C code built with clang Introduce a test that builds the low-level C bits with clang and runs unit tests. This should ensure code can also be built with clang and we get an early heads up if gcc specific bits are incoming. Signed-off-by: Maciej Borzecki --- tests/unit/c-unit-tests-clang/task.yaml | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/unit/c-unit-tests-clang/task.yaml diff --git a/tests/unit/c-unit-tests-clang/task.yaml b/tests/unit/c-unit-tests-clang/task.yaml new file mode 100644 index 00000000000..afee608f5bb --- /dev/null +++ b/tests/unit/c-unit-tests-clang/task.yaml @@ -0,0 +1,38 @@ +summary: Build the test suite for C code using clang and run it +prepare: | + # Sanity check, the core snap is installed + snap info core | MATCH "installed:" + # Install build dependencies for the test + dpkg --get-selections > pkg-list + # Remove any autogarbage from sent by developer + rm -rf "$SPREAD_PATH/cmd/"{autom4te.cache,configure,test-driver,config.status,config.guess,config.sub,config.h.in,compile,install-sh,depcomp,build,missing,aclocal.m4,Makefile,Makefile.in} + make -C "$SPREAD_PATH/cmd" distclean || true + # install clang + . "$TESTSLIB/pkgdb.sh" + distro_install_package clang +execute: | + # Refresh autotools build system + cd "$SPREAD_PATH/cmd/" + autoreconf --install --force + # Do an out-of-tree build in the autogarbage directory + mkdir -p "$SPREAD_PATH/cmd/autogarbage" + cd "$SPREAD_PATH/cmd/autogarbage" + EXTRA_CONF= + if [ ! -d /sys/kernel/security/apparmor ]; then + EXTRA_CONF="--disable-apparmor --disable-seccomp" + fi + CC=clang "$SPREAD_PATH/cmd/configure" \ + --prefix=/usr --libexecdir=/usr/lib/snapd --enable-nvidia-ubuntu $EXTRA_CONF + # Build and run unit tests + make check +restore: | + # Remove autogarbage leftover from testing + rm -rf "$SPREAD_PATH/cmd/"{autom4te.cache,configure,test-driver,config.status,config.guess,config.sub,config.h.in,compile,install-sh,depcomp,build,missing,aclocal.m4,Makefile,Makefile.in} + # Remove the build tree + rm -rf "$SPREAD_PATH/cmd/autogarbage/" + # Remove any installed packages + dpkg --set-selections < pkg-list + rm -f pkg-list +debug: | + # Show the test suite failure log if there's one + cat "$SPREAD_PATH/cmd/autogarbage/test-suite.log" || true From b6d40fcfbc5376be87b83dc6dfa7cb21f2b7989b Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 14:47:47 +0100 Subject: [PATCH 09/14] cmd: properly set CHECK_CFLAGS for libsnap-confine-private.a and its unit tests Signed-off-by: Maciej Borzecki --- cmd/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/Makefile.am b/cmd/Makefile.am index 943813cb240..a911c2e1b8d 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -92,6 +92,7 @@ libsnap_confine_private_a_SOURCES = \ libsnap-confine-private/string-utils.h \ libsnap-confine-private/utils.c \ libsnap-confine-private/utils.h +libsnap_confine_private_a_CFLAGS = $(CHECK_CFLAGS) if WITH_UNIT_TESTS noinst_PROGRAMS += libsnap-confine-private/unit-tests @@ -113,7 +114,7 @@ libsnap_confine_private_unit_tests_SOURCES = \ libsnap-confine-private/unit-tests.c \ libsnap-confine-private/unit-tests.h \ libsnap-confine-private/utils-test.c -libsnap_confine_private_unit_tests_CFLAGS = $(GLIB_CFLAGS) +libsnap_confine_private_unit_tests_CFLAGS = $(CHECK_CFLAGS) $(GLIB_CFLAGS) libsnap_confine_private_unit_tests_LDADD = $(GLIB_LIBS) libsnap_confine_private_unit_tests_CFLAGS += -D_ENABLE_FAULT_INJECTION libsnap_confine_private_unit_tests_STATIC = From 2ed4577d37f458ea22c7c1a9e560381d14f94ca1 Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 14:55:01 +0100 Subject: [PATCH 10/14] cmd/libsnap-confine-private: cleanup remaining declaration isn't prototype warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes 'function declaration isn’t a prototype [-Wstrict-prototypes]' warnings. Signed-off-by: Maciej Borzecki --- cmd/libsnap-confine-private/classic-test.c | 8 ++--- .../cleanup-funcs-test.c | 6 ++-- cmd/libsnap-confine-private/error-test.c | 30 +++++++++---------- cmd/libsnap-confine-private/fault-injection.h | 2 +- cmd/libsnap-confine-private/locking-test.c | 8 ++--- cmd/libsnap-confine-private/privs-test.c | 4 +-- cmd/libsnap-confine-private/privs.c | 2 +- cmd/libsnap-confine-private/privs.h | 2 +- cmd/libsnap-confine-private/snap-test.c | 8 ++--- 9 files changed, 35 insertions(+), 35 deletions(-) diff --git a/cmd/libsnap-confine-private/classic-test.c b/cmd/libsnap-confine-private/classic-test.c index 62e5b375e4a..bc69c827039 100644 --- a/cmd/libsnap-confine-private/classic-test.c +++ b/cmd/libsnap-confine-private/classic-test.c @@ -24,7 +24,7 @@ const char *os_release_classic = "" "NAME=\"Ubuntu\"\n" "VERSION=\"17.04 (Zesty Zapus)\"\n" "ID=ubuntu\n" "ID_LIKE=debian\n"; -static void test_is_on_classic() +static void test_is_on_classic(void) { g_file_set_contents("os-release.classic", os_release_classic, strlen(os_release_classic), NULL); @@ -36,7 +36,7 @@ static void test_is_on_classic() const char *os_release_core = "" "NAME=\"Ubuntu Core\"\n" "VERSION=\"16\"\n" "ID=ubuntu-core\n"; -static void test_is_on_core() +static void test_is_on_core(void) { g_file_set_contents("os-release.core", os_release_core, strlen(os_release_core), NULL); @@ -52,7 +52,7 @@ const char *os_release_classic_with_long_line = "" "ID_LIKE=debian\n" "LONG=line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line.line."; -static void test_is_on_classic_with_long_line() +static void test_is_on_classic_with_long_line(void) { g_file_set_contents("os-release.classic-with-long-line", os_release_classic, strlen(os_release_classic), @@ -62,7 +62,7 @@ static void test_is_on_classic_with_long_line() unlink("os-release.classic-with-long-line"); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/classic/on-classic", test_is_on_classic); g_test_add_func("/classic/on-classic-with-long-line", diff --git a/cmd/libsnap-confine-private/cleanup-funcs-test.c b/cmd/libsnap-confine-private/cleanup-funcs-test.c index ca58ca4e8ba..3565892f92c 100644 --- a/cmd/libsnap-confine-private/cleanup-funcs-test.c +++ b/cmd/libsnap-confine-private/cleanup-funcs-test.c @@ -22,13 +22,13 @@ static int called = 0; -void cleanup_fn(int *ptr) +static void cleanup_fn(int *ptr) { called = 1; } // Test that cleanup functions are applied as expected -static void test_cleanup_sanity() +static void test_cleanup_sanity(void) { { int test SC_CLEANUP(cleanup_fn); @@ -38,7 +38,7 @@ static void test_cleanup_sanity() g_assert_cmpint(called, ==, 1); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/cleanup/sanity", test_cleanup_sanity); } diff --git a/cmd/libsnap-confine-private/error-test.c b/cmd/libsnap-confine-private/error-test.c index 9ca7e0890ef..87cf705b0f6 100644 --- a/cmd/libsnap-confine-private/error-test.c +++ b/cmd/libsnap-confine-private/error-test.c @@ -21,7 +21,7 @@ #include #include -static void test_sc_error_init() +static void test_sc_error_init(void) { struct sc_error *err; // Create an error @@ -35,7 +35,7 @@ static void test_sc_error_init() g_assert_cmpstr(sc_error_msg(err), ==, "printer is on fire"); } -static void test_sc_error_init_from_errno() +static void test_sc_error_init_from_errno(void) { struct sc_error *err; // Create an error @@ -49,7 +49,7 @@ static void test_sc_error_init_from_errno() g_assert_cmpstr(sc_error_msg(err), ==, "printer is on fire"); } -static void test_sc_error_cleanup() +static void test_sc_error_cleanup(void) { // Check that sc_error_cleanup() is safe to use. @@ -64,7 +64,7 @@ static void test_sc_error_cleanup() g_assert_null(err); } -static void test_sc_error_domain__NULL() +static void test_sc_error_domain__NULL(void) { // Check that sc_error_domain() dies if called with NULL error. if (g_test_subprocess()) { @@ -82,7 +82,7 @@ static void test_sc_error_domain__NULL() ("cannot obtain error domain from NULL error\n"); } -static void test_sc_error_code__NULL() +static void test_sc_error_code__NULL(void) { // Check that sc_error_code() dies if called with NULL error. if (g_test_subprocess()) { @@ -99,7 +99,7 @@ static void test_sc_error_code__NULL() g_test_trap_assert_stderr("cannot obtain error code from NULL error\n"); } -static void test_sc_error_msg__NULL() +static void test_sc_error_msg__NULL(void) { // Check that sc_error_msg() dies if called with NULL error. if (g_test_subprocess()) { @@ -117,7 +117,7 @@ static void test_sc_error_msg__NULL() ("cannot obtain error message from NULL error\n"); } -static void test_sc_die_on_error__NULL() +static void test_sc_die_on_error__NULL(void) { // Check that sc_die_on_error() does nothing if called with NULL error. if (g_test_subprocess()) { @@ -128,7 +128,7 @@ static void test_sc_die_on_error__NULL() g_test_trap_assert_passed(); } -static void test_sc_die_on_error__regular() +static void test_sc_die_on_error__regular(void) { // Check that sc_die_on_error() dies if called with an error. if (g_test_subprocess()) { @@ -142,7 +142,7 @@ static void test_sc_die_on_error__regular() g_test_trap_assert_stderr("just testing\n"); } -static void test_sc_die_on_error__errno() +static void test_sc_die_on_error__errno(void) { // Check that sc_die_on_error() dies if called with an errno-based error. if (g_test_subprocess()) { @@ -156,7 +156,7 @@ static void test_sc_die_on_error__errno() g_test_trap_assert_stderr("just testing: No such file or directory\n"); } -static void test_sc_error_forward__nothing() +static void test_sc_error_forward__nothing(void) { // Check that forwarding NULL does exactly that. struct sc_error *recipient = (void *)0xDEADBEEF; @@ -165,7 +165,7 @@ static void test_sc_error_forward__nothing() g_assert_null(recipient); } -static void test_sc_error_forward__something_somewhere() +static void test_sc_error_forward__something_somewhere(void) { // Check that forwarding a real error works OK. struct sc_error *recipient = NULL; @@ -176,7 +176,7 @@ static void test_sc_error_forward__something_somewhere() g_assert_nonnull(recipient); } -static void test_sc_error_forward__something_nowhere() +static void test_sc_error_forward__something_nowhere(void) { // Check that forwarding a real error nowhere calls die() if (g_test_subprocess()) { @@ -196,7 +196,7 @@ static void test_sc_error_forward__something_nowhere() g_test_trap_assert_stderr("just testing\n"); } -static void test_sc_error_match__typical() +static void test_sc_error_match__typical(void) { // NULL error doesn't match anything. g_assert_false(sc_error_match(NULL, "domain", 42)); @@ -210,7 +210,7 @@ static void test_sc_error_match__typical() g_assert_false(sc_error_match(err, "other-domain", 1)); } -static void test_sc_error_match__NULL_domain() +static void test_sc_error_match__NULL_domain(void) { // Using a NULL domain is a fatal bug. if (g_test_subprocess()) { @@ -227,7 +227,7 @@ static void test_sc_error_match__NULL_domain() g_test_trap_assert_stderr("cannot match error to a NULL domain\n"); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/error/sc_error_init", test_sc_error_init); g_test_add_func("/error/sc_error_init_from_errno", diff --git a/cmd/libsnap-confine-private/fault-injection.h b/cmd/libsnap-confine-private/fault-injection.h index 8eee98444d0..cd7c573af08 100644 --- a/cmd/libsnap-confine-private/fault-injection.h +++ b/cmd/libsnap-confine-private/fault-injection.h @@ -60,7 +60,7 @@ void sc_break(const char *name, sc_fault_fn fn); /** * Remove all the injected faults. **/ -void sc_reset_faults(); +void sc_reset_faults(void); #endif // ifndef _ENABLE_FAULT_INJECTION diff --git a/cmd/libsnap-confine-private/locking-test.c b/cmd/libsnap-confine-private/locking-test.c index 8b45077ea99..28dd1e72e33 100644 --- a/cmd/libsnap-confine-private/locking-test.c +++ b/cmd/libsnap-confine-private/locking-test.c @@ -36,7 +36,7 @@ static void sc_set_lock_dir(const char *dir) // // The directory is automatically reset to the real value at the end of the // test. -static const char *sc_test_use_fake_lock_dir() +static const char *sc_test_use_fake_lock_dir(void) { char *lock_dir = NULL; if (g_test_subprocess()) { @@ -60,7 +60,7 @@ static const char *sc_test_use_fake_lock_dir() } // Check that locking a namespace actually flock's the mutex with LOCK_EX -static void test_sc_lock_unlock() +static void test_sc_lock_unlock(void) { const char *lock_dir = sc_test_use_fake_lock_dir(); int fd = sc_lock("foo"); @@ -86,7 +86,7 @@ static void test_sc_lock_unlock() g_assert_cmpint(err, ==, 0); } -static void test_sc_enable_sanity_timeout() +static void test_sc_enable_sanity_timeout(void) { if (g_test_subprocess()) { sc_enable_sanity_timeout(); @@ -101,7 +101,7 @@ static void test_sc_enable_sanity_timeout() g_test_trap_assert_failed(); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/locking/sc_lock_unlock", test_sc_lock_unlock); g_test_add_func("/locking/sc_enable_sanity_timeout", diff --git a/cmd/libsnap-confine-private/privs-test.c b/cmd/libsnap-confine-private/privs-test.c index 5ce05bdbff3..ac32f68147f 100644 --- a/cmd/libsnap-confine-private/privs-test.c +++ b/cmd/libsnap-confine-private/privs-test.c @@ -21,7 +21,7 @@ #include // Test that dropping permissions really works -static void test_sc_privs_drop() +static void test_sc_privs_drop(void) { if (geteuid() != 0 || getuid() == 0) { g_test_skip("run this test after chown root.root; chmod u+s"); @@ -61,7 +61,7 @@ static void test_sc_privs_drop() g_test_trap_assert_passed(); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/privs/sc_privs_drop", test_sc_privs_drop); } diff --git a/cmd/libsnap-confine-private/privs.c b/cmd/libsnap-confine-private/privs.c index 4d288207ba2..18b9587df2e 100644 --- a/cmd/libsnap-confine-private/privs.c +++ b/cmd/libsnap-confine-private/privs.c @@ -55,7 +55,7 @@ static bool sc_has_capability(const char *cap_name) return cap_flags_value == CAP_SET; } -void sc_privs_drop() +void sc_privs_drop(void) { gid_t gid = getgid(); uid_t uid = getuid(); diff --git a/cmd/libsnap-confine-private/privs.h b/cmd/libsnap-confine-private/privs.h index beecfebffc2..41a4eb5ed94 100644 --- a/cmd/libsnap-confine-private/privs.h +++ b/cmd/libsnap-confine-private/privs.h @@ -33,6 +33,6 @@ * dropped. When the process itself was started by root then this function does * nothing at all. **/ -void sc_privs_drop(); +void sc_privs_drop(void); #endif diff --git a/cmd/libsnap-confine-private/snap-test.c b/cmd/libsnap-confine-private/snap-test.c index b09fecdf459..d7ee8ff9b29 100644 --- a/cmd/libsnap-confine-private/snap-test.c +++ b/cmd/libsnap-confine-private/snap-test.c @@ -20,7 +20,7 @@ #include -static void test_verify_security_tag() +static void test_verify_security_tag(void) { // First, test the names we know are good g_assert_true(verify_security_tag("snap.name.app", "name")); @@ -77,7 +77,7 @@ static void test_verify_security_tag() } -static void test_sc_snap_name_validate() +static void test_sc_snap_name_validate(void) { struct sc_error *err = NULL; @@ -183,7 +183,7 @@ static void test_sc_snap_name_validate() } -static void test_sc_snap_name_validate__respects_error_protocol() +static void test_sc_snap_name_validate__respects_error_protocol(void) { if (g_test_subprocess()) { sc_snap_name_validate("hello world", NULL); @@ -197,7 +197,7 @@ static void test_sc_snap_name_validate__respects_error_protocol() ("snap name must use lower case letters, digits or dashes\n"); } -static void __attribute__ ((constructor)) init() +static void __attribute__ ((constructor)) init(void) { g_test_add_func("/snap/verify_security_tag", test_verify_security_tag); g_test_add_func("/snap/sc_snap_name_validate", From efd8081c9926ff31c292c781467f96885ef15c0d Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 15:07:51 +0100 Subject: [PATCH 11/14] cmd: make enabled C compiler warnings become error when building with unit tests This will allow us to catch warnings as part of CI pipeline Signed-off-by: Maciej Borzecki --- cmd/Makefile.am | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/Makefile.am b/cmd/Makefile.am index a911c2e1b8d..e6f9260f62e 100644 --- a/cmd/Makefile.am +++ b/cmd/Makefile.am @@ -9,6 +9,12 @@ noinst_LIBRARIES = CHECK_CFLAGS = -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes \ -Wno-missing-field-initializers -Wno-unused-parameter + +# Make all warnings errors when building for unit tests +if WITH_UNIT_TESTS +CHECK_CFLAGS += -Werror +endif + subdirs = snap-confine snap-discard-ns system-shutdown libsnap-confine-private # Run check-syntax when checking From 59cfa184614fe773efaa32a0e9ef64f4755c5f58 Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 16:39:54 +0100 Subject: [PATCH 12/14] cmd/autogen: allow passing of build directory through BUILD_DIR env variable Allow passing of desired build directory path in BUILD_DIR environment variable. Signed-off-by: Maciej Borzecki --- cmd/autogen.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/autogen.sh b/cmd/autogen.sh index 952de942813..a4f17f60fd7 100755 --- a/cmd/autogen.sh +++ b/cmd/autogen.sh @@ -1,7 +1,14 @@ #!/bin/sh # Welcome to the Happy Maintainer's Utility Script +# +# Set BUILD_DIR to the directory where the build will happen, otherwise $PWD +# will be used set -eux +BUILD_DIR=${BUILD_DIR:-.} +selfdir=$(dirname "$0") +SRC_DIR=$(readlink -f "$selfdir") + # We need the VERSION file to configure if [ ! -e VERSION ]; then ( cd .. && ./mkversion.sh ) @@ -46,6 +53,7 @@ case "$ID" in ;; esac -echo "Configuring with: $extra_opts" +echo "Configuring in build directory $BUILD_DIR with: $extra_opts" +mkdir -p "$BUILD_DIR" && cd "$BUILD_DIR" # shellcheck disable=SC2086 -./configure --enable-maintainer-mode --prefix=/usr $extra_opts +"${SRC_DIR}/configure" --enable-maintainer-mode --prefix=/usr $extra_opts From 5e34947e8b516f77d72d75e67be2deaec0ba9949 Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 6 Nov 2017 16:45:20 +0100 Subject: [PATCH 13/14] tests/unit/c-unit-tests-{gcc,clang}: refactor execute step to use autogen.sh Signed-off-by: Maciej Borzecki --- tests/unit/c-unit-tests-clang/task.yaml | 14 +++----------- tests/unit/c-unit-tests-gcc/task.yaml | 14 +++----------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/tests/unit/c-unit-tests-clang/task.yaml b/tests/unit/c-unit-tests-clang/task.yaml index afee608f5bb..b86fb5b82c9 100644 --- a/tests/unit/c-unit-tests-clang/task.yaml +++ b/tests/unit/c-unit-tests-clang/task.yaml @@ -11,18 +11,10 @@ prepare: | . "$TESTSLIB/pkgdb.sh" distro_install_package clang execute: | - # Refresh autotools build system cd "$SPREAD_PATH/cmd/" - autoreconf --install --force - # Do an out-of-tree build in the autogarbage directory - mkdir -p "$SPREAD_PATH/cmd/autogarbage" - cd "$SPREAD_PATH/cmd/autogarbage" - EXTRA_CONF= - if [ ! -d /sys/kernel/security/apparmor ]; then - EXTRA_CONF="--disable-apparmor --disable-seccomp" - fi - CC=clang "$SPREAD_PATH/cmd/configure" \ - --prefix=/usr --libexecdir=/usr/lib/snapd --enable-nvidia-ubuntu $EXTRA_CONF + build_dir="$SPREAD_PATH/cmd/autogarbage" + BUILD_DIR=$build_dir CC=clang ./autogen.sh + cd $build_dir # Build and run unit tests make check restore: | diff --git a/tests/unit/c-unit-tests-gcc/task.yaml b/tests/unit/c-unit-tests-gcc/task.yaml index be511c2ba7d..8d525c87fbe 100644 --- a/tests/unit/c-unit-tests-gcc/task.yaml +++ b/tests/unit/c-unit-tests-gcc/task.yaml @@ -8,18 +8,10 @@ prepare: | rm -rf "$SPREAD_PATH/cmd/"{autom4te.cache,configure,test-driver,config.status,config.guess,config.sub,config.h.in,compile,install-sh,depcomp,build,missing,aclocal.m4,Makefile,Makefile.in} make -C "$SPREAD_PATH/cmd" distclean || true execute: | - # Refresh autotools build system cd "$SPREAD_PATH/cmd/" - autoreconf --install --force - # Do an out-of-tree build in the autogarbage directory - mkdir -p "$SPREAD_PATH/cmd/autogarbage" - cd "$SPREAD_PATH/cmd/autogarbage" - EXTRA_CONF= - if [ ! -d /sys/kernel/security/apparmor ]; then - EXTRA_CONF="--disable-apparmor --disable-seccomp" - fi - "$SPREAD_PATH/cmd/configure" \ - --prefix=/usr --libexecdir=/usr/lib/snapd --enable-nvidia-ubuntu $EXTRA_CONF + build_dir="$SPREAD_PATH/cmd/autogarbage" + BUILD_DIR=$build_dir ./autogen.sh + cd $build_dir # Build and run unit tests make check restore: | From f352040a4f2c88b5fd88be6a0fe728e4b588de3f Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Tue, 7 Nov 2017 08:23:09 +0100 Subject: [PATCH 14/14] cmd/snap-confine/apparmor-support: fix implicit fallthrough ENOENT case is not expected to fall through. Signed-off-by: Maciej Borzecki --- cmd/snap-confine/apparmor-support.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/snap-confine/apparmor-support.c b/cmd/snap-confine/apparmor-support.c index 3c3bca05b32..eac0912d3e6 100644 --- a/cmd/snap-confine/apparmor-support.c +++ b/cmd/snap-confine/apparmor-support.c @@ -56,6 +56,7 @@ void sc_init_apparmor_support(struct sc_apparmor *apparmor) case ENOENT: debug ("apparmor is available but the interface but the interface is not available"); + break; case EPERM: // NOTE: fall-through case EACCES: