Vitezslav Samel (2): get_next_iface(): fix string overflow check ipfilter.c: gethostparams(): simplify menu initializers
src/ifaces.c | 1 + src/ifstats.c | 2 +- src/ipfilter.c | 84 ++++++++------------------------------------------------ src/promisc.c | 2 +- 4 files changed, 15 insertions(+), 74 deletions(-)
The destination space of ifname copy must be initialized to '\0' to make the overflow check correct. Also fix the callers to get_next_iface() to use all of the ifname space.
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/ifaces.c | 1 + src/ifstats.c | 2 +- src/promisc.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/ifaces.c b/src/ifaces.c index efc3106..2e6e780 100644 --- a/src/ifaces.c +++ b/src/ifaces.c @@ -68,6 +68,7 @@ int get_next_iface(FILE * fd, char *ifname, int n) strcpy(buf, ""); fgets(buf, 160, fd); if (strcmp(buf, "") != 0) { + memset(ifname, 0, n); strncpy(ifname, ltrim(strtok(buf, ":")), n); if (ifname[n - 1] != '\0') strcpy(ifname, ""); diff --git a/src/ifstats.c b/src/ifstats.c index 18ca3dd..d516585 100644 --- a/src/ifstats.c +++ b/src/ifstats.c @@ -115,7 +115,7 @@ void initiflist(struct iflist **list) return; }
- while (get_next_iface(fd, ifname, 12)) { + while (get_next_iface(fd, ifname, sizeof(ifname))) { if (strcmp(ifname, "") != 0) { if (ifinlist(*list, ifname)) /* ignore entry if already in */ continue; /* interface list */ diff --git a/src/promisc.c b/src/promisc.c index 53e56d4..167695c 100644 --- a/src/promisc.c +++ b/src/promisc.c @@ -50,7 +50,7 @@ void init_promisc_list(struct promisc_states **list) *list = NULL; fd = open_procnetdev();
- while (get_next_iface(fd, buf, 12)) { + while (get_next_iface(fd, buf, sizeof(buf))) { if (strcmp(buf, "") != 0) { ptmp = xmalloc(sizeof(struct promisc_states)); strcpy(ptmp->params.ifname, buf);
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/ipfilter.c | 84 ++++++++------------------------------------------------ 1 files changed, 12 insertions(+), 72 deletions(-)
diff --git a/src/ipfilter.c b/src/ipfilter.c index 813e7b7..dc3abb0 100644 --- a/src/ipfilter.c +++ b/src/ipfilter.c @@ -53,7 +53,6 @@ void gethostparams(struct hostparams *data, char *init_saddr, char *init_smask, char actual_address[30]; unsigned int maskbits;
- const char *init_yesno = "Y"; const char *WILDCARD = "0.0.0.0";
dlgwin = newwin(22, 80, (LINES - 22) / 2, (COLS - 80) / 2); @@ -110,77 +109,18 @@ void gethostparams(struct hostparams *data, char *init_saddr, char *init_smask, tx_addfield(&fields, 5, 5, 30, init_dport1); tx_addfield(&fields, 5, 5, 39, init_dport2);
- if (data->filters[F_ALL_IP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 10, init_yesno); - - if (data->filters[F_TCP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 20, init_yesno); - - if (data->filters[F_UDP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 30, init_yesno); - - if (data->filters[F_ICMP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 40, init_yesno); - - if (data->filters[F_IGMP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 50, init_yesno); - - if (data->filters[F_OSPF]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 10, init_yesno); - - if (data->filters[F_IGP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 20, init_yesno); - - if (data->filters[F_IGRP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 30, init_yesno); - - if (data->filters[F_GRE]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 40, init_yesno); - - if (data->filters[F_L2TP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 50, init_yesno); - - if (data->filters[F_IPSEC_AH]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 12, 10, init_yesno); - - if (data->filters[F_IPSEC_ESP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 12, 23, init_yesno); + tx_addfield(&fields, 1, 8, 10, (data->filters[F_ALL_IP]) ? "Y" : ""); + tx_addfield(&fields, 1, 8, 20, (data->filters[F_TCP]) ? "Y" : ""); + tx_addfield(&fields, 1, 8, 30, (data->filters[F_UDP]) : "Y" : ""); + tx_addfield(&fields, 1, 8, 40, (data->filters[F_ICMP]) ? "Y" : ""); + tx_addfield(&fields, 1, 8, 50, (data->filters[F_IGMP]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 10, (data->filters[F_OSPF]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 20, (data->filters[F_IGP]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 30, (data->filters[F_IGRP]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 40, (data->filters[F_GRE]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 50, (data->filters[F_L2TP]) ? "Y" : ""); + tx_addfield(&fields, 1, 12, 10, (data->filters[F_IPSEC_AH]) ? "Y" : ""); + tx_addfield(&fields, 1, 12, 23, (data->filters[F_IPSEC_ESP]) ? "Y" : "");
cptr = tx_ltrim(data->protolist); tx_addfield(&fields, 54, 15, 1, cptr);
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/ipfilter.c | 84 ++++++++------------------------------------------------ 1 files changed, 12 insertions(+), 72 deletions(-)
diff --git a/src/ipfilter.c b/src/ipfilter.c index 813e7b7..dc3abb0 100644 --- a/src/ipfilter.c +++ b/src/ipfilter.c @@ -53,7 +53,6 @@ void gethostparams(struct hostparams *data, char *init_saddr, char *init_smask, char actual_address[30]; unsigned int maskbits;
- const char *init_yesno = "Y"; const char *WILDCARD = "0.0.0.0";
dlgwin = newwin(22, 80, (LINES - 22) / 2, (COLS - 80) / 2); @@ -110,77 +109,18 @@ void gethostparams(struct hostparams *data, char *init_saddr, char *init_smask, tx_addfield(&fields, 5, 5, 30, init_dport1); tx_addfield(&fields, 5, 5, 39, init_dport2);
- if (data->filters[F_ALL_IP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 10, init_yesno); - - if (data->filters[F_TCP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 20, init_yesno); - - if (data->filters[F_UDP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 30, init_yesno); - - if (data->filters[F_ICMP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 40, init_yesno); - - if (data->filters[F_IGMP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 8, 50, init_yesno); - - if (data->filters[F_OSPF]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 10, init_yesno); - - if (data->filters[F_IGP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 20, init_yesno); - - if (data->filters[F_IGRP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 30, init_yesno); - - if (data->filters[F_GRE]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 40, init_yesno); - - if (data->filters[F_L2TP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 10, 50, init_yesno); - - if (data->filters[F_IPSEC_AH]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 12, 10, init_yesno); - - if (data->filters[F_IPSEC_ESP]) - init_yesno = "Y"; - else - init_yesno = ""; - tx_addfield(&fields, 1, 12, 23, init_yesno); + tx_addfield(&fields, 1, 8, 10, (data->filters[F_ALL_IP]) ? "Y" : ""); + tx_addfield(&fields, 1, 8, 20, (data->filters[F_TCP]) ? "Y" : ""); + tx_addfield(&fields, 1, 8, 30, (data->filters[F_UDP]) ? "Y" : ""); + tx_addfield(&fields, 1, 8, 40, (data->filters[F_ICMP]) ? "Y" : ""); + tx_addfield(&fields, 1, 8, 50, (data->filters[F_IGMP]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 10, (data->filters[F_OSPF]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 20, (data->filters[F_IGP]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 30, (data->filters[F_IGRP]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 40, (data->filters[F_GRE]) ? "Y" : ""); + tx_addfield(&fields, 1, 10, 50, (data->filters[F_L2TP]) ? "Y" : ""); + tx_addfield(&fields, 1, 12, 10, (data->filters[F_IPSEC_AH]) ? "Y" : ""); + tx_addfield(&fields, 1, 12, 23, (data->filters[F_IPSEC_ESP]) ? "Y" : "");
cptr = tx_ltrim(data->protolist); tx_addfield(&fields, 54, 15, 1, cptr);
iptraf-ng@lists.fedorahosted.org