|
18 | 18 | #include <math.h> |
19 | 19 | #include "xshared.h" |
20 | 20 |
|
| 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 | + |
21 | 48 | /* |
22 | 49 | * Print out any special helps. A user might like to be able to add a --help |
23 | 50 | * 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, |
161 | 188 | struct option *existing; |
162 | 189 | struct option *old; |
163 | 190 |
|
| 191 | + ensure_heap_opts(gl); |
| 192 | + |
164 | 193 | existing = gl->opts; |
165 | 194 | if (existing == NULL) |
166 | 195 | existing = gl->orig_opts; |
@@ -555,6 +584,8 @@ void command_match(struct iptables_command_state *cs) |
555 | 584 | struct xtables_match *m; |
556 | 585 | size_t size; |
557 | 586 |
|
| 587 | + ensure_heap_opts(xt_params); |
| 588 | + |
558 | 589 | existing = xt_params->opts; |
559 | 590 | if (existing == NULL) |
560 | 591 | existing = xt_params->orig_opts; |
@@ -623,6 +654,8 @@ void command_jump(struct iptables_command_state *cs) |
623 | 654 | struct option *opts; |
624 | 655 | size_t size; |
625 | 656 |
|
| 657 | + ensure_heap_opts(xt_params); |
| 658 | + |
626 | 659 | existing = xt_params->opts; |
627 | 660 | if (existing == NULL) |
628 | 661 | existing = xt_params->orig_opts; |
|
0 commit comments