|
|
9a3fa7 |
From 3f4e13d60ddbb61bc3256221a98f5c5a954f6f5c Mon Sep 17 00:00:00 2001
|
|
|
9a3fa7 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
9a3fa7 |
Date: Fri, 15 Mar 2019 17:51:28 +0100
|
|
|
9a3fa7 |
Subject: [PATCH] libxtables: Avoid calling memcpy() with NULL source
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1525980
|
|
|
9a3fa7 |
Upstream Status: iptables commit ab639f236ff85
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
commit ab639f236ff85d2f447cc6601c7ff42cefdaf853
|
|
|
9a3fa7 |
Author: Phil Sutter <phil@nwl.cc>
|
|
|
9a3fa7 |
Date: Wed Sep 19 15:16:54 2018 +0200
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
libxtables: Avoid calling memcpy() with NULL source
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
Both affected functions check if 'oldopts' is NULL once but later seem
|
|
|
9a3fa7 |
to ignore that possibility. To catch up on that, increment the pointer
|
|
|
9a3fa7 |
only if it isn't NULL, also don't copy its content into the merged
|
|
|
9a3fa7 |
options buffer in that case.
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
9a3fa7 |
Signed-off-by: Florian Westphal <fw@strlen.de>
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
9a3fa7 |
---
|
|
|
9a3fa7 |
libxtables/xtables.c | 12 ++++++++----
|
|
|
9a3fa7 |
libxtables/xtoptions.c | 12 ++++++++----
|
|
|
9a3fa7 |
2 files changed, 16 insertions(+), 8 deletions(-)
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
diff --git a/libxtables/xtables.c b/libxtables/xtables.c
|
|
|
9a3fa7 |
index 4a014e48a9f45..cf9a59d5ec095 100644
|
|
|
9a3fa7 |
--- a/libxtables/xtables.c
|
|
|
9a3fa7 |
+++ b/libxtables/xtables.c
|
|
|
9a3fa7 |
@@ -119,8 +119,10 @@ struct option *xtables_merge_options(struct option *orig_opts,
|
|
|
9a3fa7 |
* Since @oldopts also has @orig_opts already (and does so at the
|
|
|
9a3fa7 |
* start), skip these entries.
|
|
|
9a3fa7 |
*/
|
|
|
9a3fa7 |
- oldopts += num_oold;
|
|
|
9a3fa7 |
- num_old -= num_oold;
|
|
|
9a3fa7 |
+ if (oldopts != NULL) {
|
|
|
9a3fa7 |
+ oldopts += num_oold;
|
|
|
9a3fa7 |
+ num_old -= num_oold;
|
|
|
9a3fa7 |
+ }
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
merge = malloc(sizeof(*mp) * (num_oold + num_old + num_new + 1));
|
|
|
9a3fa7 |
if (merge == NULL)
|
|
|
9a3fa7 |
@@ -139,8 +141,10 @@ struct option *xtables_merge_options(struct option *orig_opts,
|
|
|
9a3fa7 |
mp->val += *option_offset;
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
/* Third, the old options */
|
|
|
9a3fa7 |
- memcpy(mp, oldopts, sizeof(*mp) * num_old);
|
|
|
9a3fa7 |
- mp += num_old;
|
|
|
9a3fa7 |
+ if (oldopts != NULL) {
|
|
|
9a3fa7 |
+ memcpy(mp, oldopts, sizeof(*mp) * num_old);
|
|
|
9a3fa7 |
+ mp += num_old;
|
|
|
9a3fa7 |
+ }
|
|
|
9a3fa7 |
xtables_free_opts(0);
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
/* Clear trailing entry */
|
|
|
9a3fa7 |
diff --git a/libxtables/xtoptions.c b/libxtables/xtoptions.c
|
|
|
9a3fa7 |
index 1ad4cb57f5836..1d3fda73dedf7 100644
|
|
|
9a3fa7 |
--- a/libxtables/xtoptions.c
|
|
|
9a3fa7 |
+++ b/libxtables/xtoptions.c
|
|
|
9a3fa7 |
@@ -91,8 +91,10 @@ xtables_options_xfrm(struct option *orig_opts, struct option *oldopts,
|
|
|
9a3fa7 |
* Since @oldopts also has @orig_opts already (and does so at the
|
|
|
9a3fa7 |
* start), skip these entries.
|
|
|
9a3fa7 |
*/
|
|
|
9a3fa7 |
- oldopts += num_orig;
|
|
|
9a3fa7 |
- num_old -= num_orig;
|
|
|
9a3fa7 |
+ if (oldopts != NULL) {
|
|
|
9a3fa7 |
+ oldopts += num_orig;
|
|
|
9a3fa7 |
+ num_old -= num_orig;
|
|
|
9a3fa7 |
+ }
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
merge = malloc(sizeof(*mp) * (num_orig + num_old + num_new + 1));
|
|
|
9a3fa7 |
if (merge == NULL)
|
|
|
9a3fa7 |
@@ -114,8 +116,10 @@ xtables_options_xfrm(struct option *orig_opts, struct option *oldopts,
|
|
|
9a3fa7 |
}
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
/* Third, the old options */
|
|
|
9a3fa7 |
- memcpy(mp, oldopts, sizeof(*mp) * num_old);
|
|
|
9a3fa7 |
- mp += num_old;
|
|
|
9a3fa7 |
+ if (oldopts != NULL) {
|
|
|
9a3fa7 |
+ memcpy(mp, oldopts, sizeof(*mp) * num_old);
|
|
|
9a3fa7 |
+ mp += num_old;
|
|
|
9a3fa7 |
+ }
|
|
|
9a3fa7 |
xtables_free_opts(0);
|
|
|
9a3fa7 |
|
|
|
9a3fa7 |
/* Clear trailing entry */
|
|
|
9a3fa7 |
--
|
|
|
9a3fa7 |
2.21.0
|
|
|
9a3fa7 |
|