The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/1320
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === They are pointless and marked optional since C11. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From d8f2dda5a5f137116e7439d7d5c57a5852478797 Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Fri, 25 Nov 2016 22:00:45 +0100 Subject: [PATCH 1/2] configure: do not allow variable length arrays There pointless and marked as optional since C11. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index cd424c4..337cd48 100644 --- a/configure.ac +++ b/configure.ac @@ -663,7 +663,7 @@ LXC_CHECK_TLS if test "x$GCC" = "xyes"; then CFLAGS="$CFLAGS -Wall" if test "x$enable_werror" = "xyes"; then - CFLAGS="$CFLAGS -Werror" + CFLAGS="$CFLAGS -Werror -Werror=vla" fi fi From 1440686ef13fb975ff7c15d5f5cd8796a090c79c Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Fri, 25 Nov 2016 22:01:20 +0100 Subject: [PATCH 2/2] tree-wide: remove any variable length arrays They are pointless and marked optional since C11. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/lxc/tools/lxc_cgroup.c | 5 ++--- src/lxc/tools/lxc_unshare.c | 2 +- src/lxc/utils.c | 11 +++++------ src/tests/concurrent.c | 2 +- src/tests/lxc-test-utils.c | 9 +++++---- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/lxc/tools/lxc_cgroup.c b/src/lxc/tools/lxc_cgroup.c index 32d333a..4027630 100644 --- a/src/lxc/tools/lxc_cgroup.c +++ b/src/lxc/tools/lxc_cgroup.c @@ -121,9 +121,8 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } } else { - int len = 4096; - char buffer[len]; - int ret = c->get_cgroup_item(c, state_object, buffer, len); + char buffer[MAXPATHLEN]; + int ret = c->get_cgroup_item(c, state_object, buffer, MAXPATHLEN); if (ret < 0) { ERROR("failed to retrieve value of '%s' for '%s:%s'", state_object, my_args.lxcpath[0], my_args.name); diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c index 72ea00c..82c8244 100644 --- a/src/lxc/tools/lxc_unshare.c +++ b/src/lxc/tools/lxc_unshare.c @@ -82,7 +82,7 @@ static void usage(char *cmd) static bool lookup_user(const char *optarg, uid_t *uid) { - char name[sysconf(_SC_LOGIN_NAME_MAX)]; + char name[MAXPATHLEN]; struct passwd *pwent = NULL; if (!optarg || (optarg[0] == '\0')) diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 200f5cd..7ddf1db 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -1896,6 +1896,8 @@ int lxc_strmunmap(void *addr, size_t length) } /* Check whether a signal is blocked by a process. */ +/* /proc/pid-to-str/status\0 = (5 + 21 + 7 + 1) */ +#define __PROC_STATUS_LEN (5 + 21 + 7 + 1) bool task_blocking_signal(pid_t pid, int signal) { bool bret = false; @@ -1905,13 +1907,10 @@ bool task_blocking_signal(pid_t pid, int signal) int ret; FILE *f; - /* The largest integer that can fit into long int is 2^64. This is a - * 20-digit number. */ - size_t len = /* /proc */ 5 + /* /pid-to-str */ 21 + /* /status */ 7 + /* \0 */ 1; - char status[len]; + char status[__PROC_STATUS_LEN]; - ret = snprintf(status, len, "/proc/%d/status", pid); - if (ret < 0 || ret >= len) + ret = snprintf(status, __PROC_STATUS_LEN, "/proc/%d/status", pid); + if (ret < 0 || ret >= __PROC_STATUS_LEN) return bret; f = fopen(status, "r"); diff --git a/src/tests/concurrent.c b/src/tests/concurrent.c index e6899ad..1d59a51 100644 --- a/src/tests/concurrent.c +++ b/src/tests/concurrent.c @@ -85,7 +85,7 @@ static void do_function(void *arguments) } if (debug) { - c->set_config_item(c, "lxc.loglevel", "DEBUG"); + c->set_config_item(c, "lxc.loglevel", "WARN"); c->set_config_item(c, "lxc.logfile", name); } diff --git a/src/tests/lxc-test-utils.c b/src/tests/lxc-test-utils.c index e32415b..800c029 100644 --- a/src/tests/lxc-test-utils.c +++ b/src/tests/lxc-test-utils.c @@ -70,13 +70,14 @@ void test_lxc_deslashify(void) free(s); } +/* /proc/int_as_str/ns/mnt\0 = (5 + 21 + 7 + 1) */ +#define __MNTNS_LEN (5 + 21 + 7 + 1) void test_detect_ramfs_rootfs(void) { size_t i; int ret; int fret = EXIT_FAILURE; - size_t len = 5 /* /proc */ + 21 /* /int_as_str */ + 7 /* /ns/mnt */ + 1 /* \0 */; - char path[len]; + char path[__MNTNS_LEN]; int init_ns = -1; char tmpf1[] = "lxc-test-utils-XXXXXX"; char tmpf2[] = "lxc-test-utils-XXXXXX"; @@ -118,8 +119,8 @@ void test_detect_ramfs_rootfs(void) "78 24 8:1 / /boot/efi rw,relatime shared:30 - vfat /dev/sda1 rw,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro", }; - ret = snprintf(path, len, "/proc/self/ns/mnt"); - if (ret < 0 || (size_t)ret >= len) { + ret = snprintf(path, __MNTNS_LEN, "/proc/self/ns/mnt"); + if (ret < 0 || (size_t)ret >= __MNTNS_LEN) { lxc_error("%s\n", "Failed to create path with snprintf()."); goto non_test_error; }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel