All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2] Fix segv on "-r" option if unknown rpc service
Date: Thu, 22 Sep 2022 12:01:05 -0700	[thread overview]
Message-ID: <20220922120105.7a200fd2@hermes.local> (raw)
In-Reply-To: <87tu55q48x.fsf@mail.parknet.co.jp>

On Sun, 18 Sep 2022 02:50:54 +0900
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> wrote:

> +		} else {
> +			const char fmt[] = "%s%u";
> +			char *buf = NULL;
> +			int len = snprintf(buf, 0, fmt, prog,
> +					   rhead->rpcb_map.r_prog);
> +			len++;
> +			buf = malloc(len);
> +			snprintf(buf, len, fmt, prog, rhead->rpcb_map.r_prog);
> +			c->name = buf;
>  		}

Thanks for finding the bug but this could be improved.
This seems like the hard way to do this.
You are reinventing asprintf().

Would this work instead.

diff --git a/misc/ss.c b/misc/ss.c
index ff985cd8cae9..9d3d0bd84df3 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1596,6 +1596,10 @@ static void init_service_resolver(void)
                if (rpc) {
                        strncat(prog, rpc->r_name, 128 - strlen(prog));
                        c->name = strdup(prog);
+               } else if (asprintf(&c->name, "%s%u",
+                                   prog, rhead->rpcb_map.r_prog) < 0) {
+                       fprintf(stderr, "ss: asprintf failed to allocate buffer\n");
+                       abort();
                }
 
                c->next = rlist;

  reply	other threads:[~2022-09-22 19:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-17 17:50 [PATCH iproute2] Fix segv on "-r" option if unknown rpc service OGAWA Hirofumi
2022-09-22 19:01 ` Stephen Hemminger [this message]
2022-09-22 20:31   ` OGAWA Hirofumi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220922120105.7a200fd2@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.