* [PATCH iproute2] Fix segv on "-r" option if unknown rpc service
@ 2022-09-17 17:50 OGAWA Hirofumi
2022-09-22 19:01 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: OGAWA Hirofumi @ 2022-09-17 17:50 UTC (permalink / raw)
To: netdev; +Cc: Stephen Hemminger
In init_service_resolver(), if getrpcbynumber() returned NULL, c->name
is pointing the undefined memory. So "-r" can segv for example.
So this patch uses "rpc.<r_prog>" format like the following if rpc
name is unresolved, instead of segv or raw port number.
tcp LISTEN 0 64 0.0.0.0:rpc.100227 0.0.0.0:*
[Or we would be able to set c->name = NULL to use raw port number]
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
misc/ss.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/misc/ss.c b/misc/ss.c
index ff985cd..866e278 100644
--- a/misc/ss.c 2022-08-25 16:22:06.454913793 +0900
+++ b/misc/ss.c 2022-09-18 02:48:24.212779850 +0900
@@ -1596,6 +1596,15 @@ static void init_service_resolver(void)
if (rpc) {
strncat(prog, rpc->r_name, 128 - strlen(prog));
c->name = strdup(prog);
+ } 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;
}
c->next = rlist;
_
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2] Fix segv on "-r" option if unknown rpc service
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
2022-09-22 20:31 ` OGAWA Hirofumi
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2022-09-22 19:01 UTC (permalink / raw)
To: OGAWA Hirofumi; +Cc: netdev
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;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2] Fix segv on "-r" option if unknown rpc service
2022-09-22 19:01 ` Stephen Hemminger
@ 2022-09-22 20:31 ` OGAWA Hirofumi
0 siblings, 0 replies; 3+ messages in thread
From: OGAWA Hirofumi @ 2022-09-22 20:31 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Stephen Hemminger <stephen@networkplumber.org> writes:
> 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().
Right, if this project is assuming the extension is available.
> Would this work instead.
Thanks.
> 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;
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-22 20:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2022-09-22 20:31 ` OGAWA Hirofumi
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.