[lxc-devel] [lxc/master] tree-wide: Sic semper assertis!

brauner on Github lxc-bot at linuxcontainers.org
Wed Jan 4 09:48:32 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170104/f8676b02/attachment.bin>
-------------- next part --------------
From 96b98f85843f0e9629a9a3efbaad712af00bb11f Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 4 Jan 2017 10:28:25 +0100
Subject: [PATCH] tree-wide: Sic semper assertis!

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/console.c          |  9 ++++++---
 src/lxc/criu.c             |  1 -
 src/lxc/log.c              |  4 ++--
 src/lxc/lxccontainer.c     |  7 +++++--
 src/lxc/tools/lxc_attach.c |  7 ++++---
 src/lxc/utils.c            | 11 ++++++++---
 6 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/src/lxc/console.c b/src/lxc/console.c
index 052512e..908ead0 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -21,7 +21,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -577,7 +576,9 @@ int lxc_console_cb_tty_stdin(int fd, uint32_t events, void *cbdata,
 	struct lxc_tty_state *ts = cbdata;
 	char c;
 
-	assert(fd == ts->stdinfd);
+	if (fd != ts->stdinfd)
+		return 1;
+
 	if (lxc_read_nointr(ts->stdinfd, &c, 1) <= 0)
 		return 1;
 
@@ -607,7 +608,9 @@ int lxc_console_cb_tty_master(int fd, uint32_t events, void *cbdata,
 	char buf[1024];
 	int r, w;
 
-	assert(fd == ts->masterfd);
+	if (fd != ts->masterfd)
+		return 1;
+
 	r = lxc_read_nointr(fd, buf, sizeof(buf));
 	if (r <= 0)
 		return 1;
diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index 125e674..53c368b 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -21,7 +21,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #define _GNU_SOURCE
-#include <assert.h>
 #include <inttypes.h>
 #include <linux/limits.h>
 #include <sched.h>
diff --git a/src/lxc/log.c b/src/lxc/log.c
index 48c78b3..cdeec9f 100644
--- a/src/lxc/log.c
+++ b/src/lxc/log.c
@@ -23,7 +23,6 @@
 
 #define _GNU_SOURCE
 #define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
-#include <assert.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <errno.h>
@@ -470,7 +469,8 @@ static int __lxc_log_set_file(const char *fname, int create_dirs)
 		lxc_log_close();
 	}
 
-	assert(fname != NULL);
+	if (!fname)
+		return -1;
 
 	if (strlen(fname) == 0) {
 		log_fname = NULL;
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index d96d23e..4b0a195 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -19,7 +19,6 @@
  */
 
 #define _GNU_SOURCE
-#include <assert.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -4402,7 +4401,11 @@ int list_active_containers(const char *lxcpath, char ***nret,
 		cret_cnt++;
 	}
 
-	assert(!nret || !cret || cret_cnt == ct_name_cnt);
+	if (nret && cret && cret_cnt != ct_name_cnt) {
+		lxc_container_put(c);
+		goto free_cret_list;
+	}
+
 	ret = ct_name_cnt;
 	if (nret)
 		*nret = ct_name;
diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
index 4dd3883..acc3dcf 100644
--- a/src/lxc/tools/lxc_attach.c
+++ b/src/lxc/tools/lxc_attach.c
@@ -23,7 +23,6 @@
 
 #include "config.h"
 
-#include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -83,7 +82,8 @@ static int add_to_simple_array(char ***array, ssize_t *capacity, char *value)
 {
 	ssize_t count = 0;
 
-	assert(array);
+	if (!array)
+		return -1;
 
 	if (*array)
 		for (; (*array)[count]; count++);
@@ -99,7 +99,8 @@ static int add_to_simple_array(char ***array, ssize_t *capacity, char *value)
 		*capacity = new_capacity;
 	}
 
-	assert(*array);
+	if (!(*array))
+		return -1;
 
 	(*array)[count] = value;
 	return 0;
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 7c2098e..2a0f05a 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -23,7 +23,6 @@
 
 #include "config.h"
 
-#include <assert.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -639,10 +638,16 @@ char *lxc_string_replace(const char *needle, const char *replacement, const char
 	/* make sure we did the same thing twice,
 	 * once for calculating length, the other
 	 * time for copying data */
-	assert(saved_len == len);
+	if (saved_len != len) {
+		free(result);
+		return NULL;
+	}
 	/* make sure we didn't overwrite any buffer,
 	 * due to calloc the string should be 0-terminated */
-	assert(result[len] == '\0');
+	if (result[len] != '\0') {
+		free(result);
+		return NULL;
+	}
 
 	return result;
 }


More information about the lxc-devel mailing list