Covscan: Don't access garbage
Subsystems (2)
PATCH v3 4/6 ss: Use C99 initializer in netlink_show_one()
In reply to Phil SutterThis has the additional benefit of initializing st.ino to zero which is used later in is_sctp_assoc() function.
--- misc/ss.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
misc/ss.c +7 -6
@@ -3480,17 +3480,18 @@ static int netlink_show_one(struct filter *f, int rq, int wq, unsigned long long sk, unsigned long long cb) { - struct sockstat st; + struct sockstat st = { + .state =SS_CLOSE , + .rq = rq, + .wq = wq, + .local.family =AF_NETLINK , + .remote.family =AF_NETLINK , + };SPRINT_BUF (prot_buf) = {};const char *prot_name;char procname[64 ] = {}; - st.state =SS_CLOSE ; - st.rq = rq; - st.wq = wq; - st.local.family = st.remote.family =AF_NETLINK ; -if (f->f) { st.rport =-1 ; st.lport = pid;
Signature · 1 line
2.13.1
PATCH v3 3/6 ipmaddr: Avoid accessing uninitialized data
In reply to Phil SutterLooks like this can only happen if /proc/net/igmp is malformed, but better be sure.
--- ip/ipmaddr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/ipmaddr.c +1 -1
@@ -136,7 +136,7 @@ static void read_igmp(struct ma_info **result_p)while (fgets (buf,sizeof (buf), fp)) {struct ma_info *ma; -size_t len; +size_t len =0 ;if (buf[0 ] !='\t' ) {sscanf (buf,"%d%s" , &m.index, m.name);
Signature · 1 line
2.13.1
v3 cover Covscan: Don't access garbage
This series collects patches from v1 which resolve situations where garbage might be read, either due to missing initialization of variables or accessing data which went out of scope.
Changes since v2:
- Rebased onto current master branch.
- Dropped first patch since it is not a real issue.
Phil Sutter (6):
ipaddress: Avoid accessing uninitialized variable lcl
iplink_can: Prevent overstepping array bounds
ipmaddr: Avoid accessing uninitialized data
ss: Use C99 initializer in netlink_show_one() netem/maketable: Check return value of fstat() tc/q_multiq: Don't pass garbage in TCA_OPTIONS
ip/ipaddress.c | 2 +- ip/iplink_can.c | 4 ++-- ip/ipmaddr.c | 2 +- misc/ss.c | 13 +++++++------ netem/maketable.c | 4 ++-- tc/q_multiq.c | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-)
Signature · 1 line
2.13.1
PATCH v3 1/6 ipaddress: Avoid accessing uninitialized variable lcl
If no address was given, ipaddr_modify() accesses uninitialized data when assigning to req.ifa.ifa_prefixlen.
--- ip/ipaddress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ip/ipaddress.c +1 -1
@@ -1888,7 +1888,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)char *lcl_arg =NULL ;char *valid_lftp =NULL ;char *preferred_lftp =NULL ; -inet_prefix lcl; +inet_prefix lcl = {};inet_prefix peer;int local_len =0 ;int peer_len =0 ;
Signature · 1 line
2.13.1
PATCH v3 6/6 tc/q_multiq: Don't pass garbage in TCA_OPTIONS
In reply to Phil Suttermultiq_parse_opt() doesn't change 'opt' at all. So at least make sure it doesn't fill TCA_OPTIONS attribute with garbage from stack.
--- tc/q_multiq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tc/q_multiq.c +1 -1
@@ -43,7 +43,7 @@ static void explain(void)static int multiq_parse_opt (struct qdisc_util *qu,int argc,char **argv,struct nlmsghdr *n) { -struct tc_multiq_qopt opt; +struct tc_multiq_qopt opt = {};if (argc) {if (strcmp (*argv,"help" ) ==0 ) {
Signature · 1 line
2.13.1
PATCH v3 5/6 netem/maketable: Check return value of fstat()
In reply to Phil SutterOtherwise info.st_size may contain garbage.
--- netem/maketable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
netem/maketable.c +2 -2
@@ -24,8 +24,8 @@ readdoubles(FILE *fp, int *number)int limit;int n=0 , i; -fstat (fileno (fp), &info); -if (info.st_size >0 ) { +if (!fstat (fileno (fp), &info) && + info.st_size >0 ) { limit =2 *info.st_size/sizeof (double );/* @@ approximate */ }else { limit =10000 ;
Signature · 1 line
2.13.1
PATCH v3 2/6 iplink_can: Prevent overstepping array bounds
In reply to Phil Suttercan_state_names array contains at most CAN_STATE_MAX fields, so allowing an index to it to be equal to that number is wrong. While here, also make sure the array is indeed that big so nothing bad happens if CAN_STATE_MAX ever increases.
--- ip/iplink_can.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
ip/iplink_can.c +2 -2
@@ -251,7 +251,7 @@ static int can_parse_opt(struct link_util *lu, int argc, char **argv,return 0 ; } -static const char *can_state_names[] = { +static const char *can_state_names[CAN_STATE_MAX ] = { [CAN_STATE_ERROR_ACTIVE ] ="ERROR-ACTIVE" , [CAN_STATE_ERROR_WARNING ] ="ERROR-WARNING" , [CAN_STATE_ERROR_PASSIVE ] ="ERROR-PASSIVE" ,
@@ -275,7 +275,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])if (tb[IFLA_CAN_STATE ]) {uint32_t state =rta_getattr_u32 (tb[IFLA_CAN_STATE ]); -fprintf (f,"state %s " , state <=CAN_STATE_MAX ? +fprintf (f,"state %s " , state <CAN_STATE_MAX ? can_state_names[state] :"UNKNOWN" ); }
Signature · 1 line
2.13.1
Quoted 16 lines · On Mon, 21 Aug 2017 11:26:58 +0200 Phil Sutter <[email protected]> wrote:
This series collects patches from v1 which resolve situations where garbage might be read, either due to missing initialization of variables or accessing data which went out of scope.
Changes since v2:
- Rebased onto current master branch.
- Dropped first patch since it is not a real issue.Phil Sutter (6):
ipaddress: Avoid accessing uninitialized variable lcl
iplink_can: Prevent overstepping array bounds
ipmaddr: Avoid accessing uninitialized data
ss: Use C99 initializer innetlink_show_one()netem/maketable: Check return value offstat()tc/q_multiq: Don't pass garbage inTCA_OPTIONS
Quoted 8 lines
ip/ipaddress.c | 2 +- ip/iplink_can.c | 4 ++-- ip/ipmaddr.c | 2 +- misc/ss.c | 13 +++++++------ netem/maketable.c | 4 ++-- tc/q_multiq.c | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-)
These look fine. Applied.