]> git.proxmox.com Git - mirror_iproute2.git/commit
ss: Fix allocation of cong control alg name
authorEric Dumazet <eric.dumazet@gmail.com>
Fri, 29 May 2015 11:04:05 +0000 (04:04 -0700)
committerStephen Hemminger <shemming@brocade.com>
Thu, 25 Jun 2015 03:11:33 +0000 (23:11 -0400)
commitd2055ea597e571bbbb6468b23b9c85de5ebf4591
treeb0f8d23808be02ef74ae1671bd9d53715a326470
parentb6907403efd9d64ed5a140d3bc6e23773452bef9
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.
misc/ss.c