|
|
104ea9 |
From d70c640aecc30e9216dc1a614a207e85c8732036 Mon Sep 17 00:00:00 2001
|
|
|
104ea9 |
From: Colin Walters <walters@verbum.org>
|
|
|
104ea9 |
Date: Thu, 27 May 2021 16:19:27 -0400
|
|
|
104ea9 |
Subject: [PATCH] Avoid memory leak if --args is specified multiple times
|
|
|
104ea9 |
|
|
|
104ea9 |
Found by a static analyzer.
|
|
|
104ea9 |
|
|
|
104ea9 |
```
|
|
|
104ea9 |
bubblewrap-0.4.1/bubblewrap.c:1500: overwrite_var: Overwriting "opt_args_data" in "opt_args_data = load_file_data(the_fd, &data_len)" leaks the storage that "opt_args_data" points to.
|
|
|
104ea9 |
# 1498| * keep allocated until exit time, since its argv entries get used
|
|
|
104ea9 |
# 1499| * by the other cases in parse_args_recurse() when we recurse. */
|
|
|
104ea9 |
# 1500|-> opt_args_data = load_file_data (the_fd, &data_len);
|
|
|
104ea9 |
# 1501| if (opt_args_data == NULL)
|
|
|
104ea9 |
# 1502| die_with_error ("Can't read --args data");
|
|
|
104ea9 |
```
|
|
|
104ea9 |
---
|
|
|
104ea9 |
bubblewrap.c | 6 ++++++
|
|
|
104ea9 |
1 file changed, 6 insertions(+)
|
|
|
104ea9 |
|
|
|
104ea9 |
diff --git a/bubblewrap.c b/bubblewrap.c
|
|
|
104ea9 |
index 771e1ea..56ac07c 100644
|
|
|
104ea9 |
--- a/bubblewrap.c
|
|
|
104ea9 |
+++ b/bubblewrap.c
|
|
|
104ea9 |
@@ -1494,6 +1494,12 @@ parse_args_recurse (int *argcp,
|
|
|
104ea9 |
if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0)
|
|
|
104ea9 |
die ("Invalid fd: %s", argv[1]);
|
|
|
104ea9 |
|
|
|
104ea9 |
+ /* Specifying --args multiple times doesn't work; this just pacifies
|
|
|
104ea9 |
+ * a static analyzer which pointed out the memory leak
|
|
|
104ea9 |
+ */
|
|
|
104ea9 |
+ if (opt_args_data != NULL)
|
|
|
104ea9 |
+ free (opt_args_data);
|
|
|
104ea9 |
+
|
|
|
104ea9 |
/* opt_args_data is essentially a recursive argv array, which we must
|
|
|
104ea9 |
* keep allocated until exit time, since its argv entries get used
|
|
|
104ea9 |
* by the other cases in parse_args_recurse() when we recurse. */
|
|
|
104ea9 |
--
|
|
|
104ea9 |
2.31.1
|
|
|
104ea9 |
|