Skip to content

Commit df386eb

Browse files
committed
...
1 parent d4ce54c commit df386eb

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

ipthelper/ip6tables.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,26 +1439,25 @@ int do_command6(int argc, char *argv[], char **table, void **handle)
14391439
opterr = 0;
14401440

14411441
/* Create a malloc'd copy of orig_opts */
1442+
size_t num_opts = 0;
1443+
struct option *orig_opts = iptables_globals.orig_opts;
1444+
1445+
/* Count the number of options (including the NULL terminator) */
1446+
while (orig_opts[num_opts].name != NULL) {
1447+
num_opts++;
1448+
}
1449+
num_opts++; /* Include the NULL terminator */
1450+
1451+
/* Allocate memory and copy the options */
1452+
iptables_globals.opts = malloc(num_opts * sizeof(struct option));
14421453
if (iptables_globals.opts == NULL) {
1443-
size_t num_opts = 0;
1444-
struct option *orig_opts = iptables_globals.orig_opts;
1445-
1446-
/* Count the number of options (including the NULL terminator) */
1447-
while (orig_opts[num_opts].name != NULL) {
1448-
num_opts++;
1449-
}
1450-
num_opts++; /* Include the NULL terminator */
1451-
1452-
/* Allocate memory and copy the options */
1453-
iptables_globals.opts = malloc(num_opts * sizeof(struct option));
1454-
if (iptables_globals.opts == NULL) {
1455-
xtables_error(OTHER_PROBLEM, "malloc failed for options array");
1456-
}
1457-
memcpy(iptables_globals.opts, iptables_globals.orig_opts, num_opts * sizeof(struct option));
1454+
xtables_error(OTHER_PROBLEM, "malloc failed for options array");
14581455
}
1456+
memcpy(iptables_globals.opts, iptables_globals.orig_opts, num_opts * sizeof(struct option));
1457+
14591458
while ((cs.c = getopt_long(argc, argv,
14601459
"-:A:C:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:bvnt:m:xc:g:46",
1461-
iptables_globals.opts?: iptables_globals.orig_opts, NULL)) != -1) {
1460+
iptables_globals.opts, NULL)) != -1) {
14621461
switch (cs.c) {
14631462
/*
14641463
* Command selection

ipthelper/iptables.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,26 +1018,25 @@ int do_command4(int argc, char *argv[], char **table, void **handle)
10181018
opterr = 0;
10191019

10201020
/* Create a malloc'd copy of orig_opts */
1021+
size_t num_opts = 0;
1022+
struct option *orig_opts = iptables_globals.orig_opts;
1023+
1024+
/* Count the number of options (including the NULL terminator) */
1025+
while (orig_opts[num_opts].name != NULL) {
1026+
num_opts++;
1027+
}
1028+
num_opts++; /* Include the NULL terminator */
1029+
1030+
/* Allocate memory and copy the options */
1031+
iptables_globals.opts = malloc(num_opts * sizeof(struct option));
10211032
if (iptables_globals.opts == NULL) {
1022-
size_t num_opts = 0;
1023-
struct option *orig_opts = iptables_globals.orig_opts;
1024-
1025-
/* Count the number of options (including the NULL terminator) */
1026-
while (orig_opts[num_opts].name != NULL) {
1027-
num_opts++;
1028-
}
1029-
num_opts++; /* Include the NULL terminator */
1030-
1031-
/* Allocate memory and copy the options */
1032-
iptables_globals.opts = malloc(num_opts * sizeof(struct option));
1033-
if (iptables_globals.opts == NULL) {
1034-
xtables_error(OTHER_PROBLEM, "malloc failed for options array");
1035-
}
1036-
memcpy(iptables_globals.opts, iptables_globals.orig_opts, num_opts * sizeof(struct option));
1033+
xtables_error(OTHER_PROBLEM, "malloc failed for options array");
10371034
}
1035+
memcpy(iptables_globals.opts, iptables_globals.orig_opts, num_opts * sizeof(struct option));
1036+
10381037
while ((cs.c = getopt_long(argc, argv,
10391038
"-:A:C:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:fbvnt:m:xc:g:46",
1040-
iptables_globals.opts?: iptables_globals.orig_opts,
1039+
iptables_globals.opts,
10411040
NULL)) != -1) {
10421041
switch (cs.c) {
10431042
/*

0 commit comments

Comments
 (0)