Skip to content

Commit a31f04a

Browse files
committed
Update xshared.c
1 parent afdb17e commit a31f04a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

ipthelper/xshared.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,33 @@
1818
#include <math.h>
1919
#include "xshared.h"
2020

21+
static void ensure_heap_opts(struct xtables_globals *globals)
22+
{
23+
struct option *orig;
24+
size_t count;
25+
struct option *copy;
26+
27+
if (globals == NULL)
28+
return;
29+
30+
if (globals->opts == NULL)
31+
globals->opts = globals->orig_opts;
32+
33+
orig = globals->orig_opts;
34+
if (orig == NULL || globals->opts != orig)
35+
return;
36+
37+
for (count = 0; orig[count].name != NULL; ++count)
38+
;
39+
copy = malloc(sizeof(*copy) * (count + 1));
40+
if (copy == NULL)
41+
xtables_error(RESOURCE_PROBLEM, "malloc");
42+
memcpy(copy, orig, sizeof(*copy) * (count + 1));
43+
globals->opts = copy;
44+
if (xt_params == globals)
45+
xt_params->opts = copy;
46+
}
47+
2148
/*
2249
* Print out any special helps. A user might like to be able to add a --help
2350
* to the commandline, and see expected results. So we call help for all
@@ -161,6 +188,8 @@ int command_default(struct iptables_command_state *cs,
161188
struct option *existing;
162189
struct option *old;
163190

191+
ensure_heap_opts(gl);
192+
164193
existing = gl->opts;
165194
if (existing == NULL)
166195
existing = gl->orig_opts;
@@ -555,6 +584,8 @@ void command_match(struct iptables_command_state *cs)
555584
struct xtables_match *m;
556585
size_t size;
557586

587+
ensure_heap_opts(xt_params);
588+
558589
existing = xt_params->opts;
559590
if (existing == NULL)
560591
existing = xt_params->orig_opts;
@@ -623,6 +654,8 @@ void command_jump(struct iptables_command_state *cs)
623654
struct option *opts;
624655
size_t size;
625656

657+
ensure_heap_opts(xt_params);
658+
626659
existing = xt_params->opts;
627660
if (existing == NULL)
628661
existing = xt_params->orig_opts;

0 commit comments

Comments
 (0)