iproute2/misc
Eric Dumazet d2055ea597 ss: Fix allocation of cong control alg name
On Fri, 2015-05-29 at 13:30 +0300, Vadim Kochan wrote:
> From: Vadim Kochan <vadim4j@gmail.com>
>
> Use strdup instead of malloc, and get rid of bad strcpy.
>
> Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
> ---
>  misc/ss.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/misc/ss.c b/misc/ss.c
> index 347e3a1..a719466 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -1908,8 +1908,7 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
>
>  		if (tb[INET_DIAG_CONG]) {
>  			const char *cong_attr = rta_getattr_str(tb[INET_DIAG_CONG]);
> -			s.cong_alg = malloc(strlen(cong_attr + 1));
> -			strcpy(s.cong_alg, cong_attr);
> +			s.cong_alg = strdup(cong_attr);
>  		}
>
>  		if (TCPI_HAS_OPT(info, TCPI_OPT_WSCALE)) {

I doubt TCP_CA_NAME_MAX will ever change in the kernel : 16 bytes.

Its typically "cubic" and less than 8 bytes.

Using 8 bytes to point to a malloc(8) is a waste.

Please remove the memory allocation, or store the pointer, since
tcp_show_info() does the malloc()/free() before return.
2015-06-24 23:11:33 -04:00
..
.gitignore Add ignore files to make using git easier 2006-08-08 12:04:38 -07:00
Makefile ss: Show stats from specified network namespace 2015-02-10 15:11:59 -08:00
arpd.c whitespace cleanup 2014-12-20 15:47:17 -08:00
ifstat.c whitespace cleanup 2014-12-20 15:47:17 -08:00
lnstat.c lnstat: dump to stdout, not stderr 2015-04-20 09:58:46 -07:00
lnstat.h iproute2: various header include fixes for compiling with musl libc 2014-05-28 16:51:39 -07:00
lnstat_util.c Remove trailing whitespace 2006-12-05 10:10:22 -08:00
nstat.c iproute2/nstat: Bug in displaying icmp stats 2014-12-09 20:33:32 -08:00
rtacct.c ip: make local functions static 2013-02-12 11:38:35 -08:00
ss.c ss: Fix allocation of cong control alg name 2015-06-24 23:11:33 -04:00
ssfilter.h ss: Allow to specify sport/dport without ':' 2015-03-15 12:11:42 -07:00
ssfilter.y ss: Allow to specify sport/dport without ':' 2015-03-15 12:11:42 -07:00