* [iproute PATCH v2] ipaddress: Fix segfault in 'addr showdump'
@ 2017-09-13 9:20 Phil Sutter
2017-09-15 3:05 ` Julien Fortin
2017-09-21 0:54 ` Stephen Hemminger
0 siblings, 2 replies; 3+ messages in thread
From: Phil Sutter @ 2017-09-13 9:20 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Hangbin Liu, netdev, Julien Fortin
Obviously, 'addr showdump' feature wasn't adjusted to json output
support. As a consequence, calls to print_string() in print_addrinfo()
tried to dereference a NULL FILE pointer.
Cc: Julien Fortin <julien@cumulusnetworks.com>
Fixes: d0e720111aad2 ("ip: ipaddress.c: add support for json output")
Signed-off-by: Phil Sutter <phil@nwl.cc>
--
Changes since v1:
Align json output with that of 'ip -j addr show':
- Interface index label is 'ifindex', not 'index' and it doesn't belong
to 'addr_info' array.
- Create one 'addr_info' array per dumped address, not one for all.
---
ip/ipaddress.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 9797145023966..4c47809570410 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -1801,17 +1801,33 @@ static int show_handler(const struct sockaddr_nl *nl,
{
struct ifaddrmsg *ifa = NLMSG_DATA(n);
- printf("if%d:\n", ifa->ifa_index);
+ open_json_object(NULL);
+ print_int(PRINT_ANY, "ifindex", "if%d:\n", ifa->ifa_index);
+
+ open_json_array(PRINT_JSON, "addr_info");
+ open_json_object(NULL);
+
print_addrinfo(NULL, n, stdout);
+
+ close_json_object();
+ close_json_array(PRINT_JSON, NULL);
+
+ close_json_object();
return 0;
}
static int ipaddr_showdump(void)
{
+ int err;
+
if (ipadd_dump_check_magic())
exit(-1);
- exit(rtnl_from_file(stdin, &show_handler, NULL));
+ new_json_obj(json, stdout);
+ err = rtnl_from_file(stdin, &show_handler, NULL);
+ delete_json_obj();
+
+ exit(err);
}
static int restore_handler(const struct sockaddr_nl *nl,
--
2.13.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [iproute PATCH v2] ipaddress: Fix segfault in 'addr showdump'
2017-09-13 9:20 [iproute PATCH v2] ipaddress: Fix segfault in 'addr showdump' Phil Sutter
@ 2017-09-15 3:05 ` Julien Fortin
2017-09-21 0:54 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Julien Fortin @ 2017-09-15 3:05 UTC (permalink / raw)
To: Phil Sutter; +Cc: Stephen Hemminger, Hangbin Liu, netdev
v2 looks good to me, thanks for catching this segfault.
On Wed, Sep 13, 2017 at 2:20 AM, Phil Sutter <phil@nwl.cc> wrote:
> Obviously, 'addr showdump' feature wasn't adjusted to json output
> support. As a consequence, calls to print_string() in print_addrinfo()
> tried to dereference a NULL FILE pointer.
>
> Cc: Julien Fortin <julien@cumulusnetworks.com>
> Fixes: d0e720111aad2 ("ip: ipaddress.c: add support for json output")
> Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Julien Fortin <julien@cumulusnetworks.com>
> --
> Changes since v1:
> Align json output with that of 'ip -j addr show':
> - Interface index label is 'ifindex', not 'index' and it doesn't belong
> to 'addr_info' array.
> - Create one 'addr_info' array per dumped address, not one for all.
> ---
> ip/ipaddress.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/ip/ipaddress.c b/ip/ipaddress.c
> index 9797145023966..4c47809570410 100644
> --- a/ip/ipaddress.c
> +++ b/ip/ipaddress.c
> @@ -1801,17 +1801,33 @@ static int show_handler(const struct sockaddr_nl *nl,
> {
> struct ifaddrmsg *ifa = NLMSG_DATA(n);
>
> - printf("if%d:\n", ifa->ifa_index);
> + open_json_object(NULL);
> + print_int(PRINT_ANY, "ifindex", "if%d:\n", ifa->ifa_index);
> +
> + open_json_array(PRINT_JSON, "addr_info");
> + open_json_object(NULL);
> +
> print_addrinfo(NULL, n, stdout);
> +
> + close_json_object();
> + close_json_array(PRINT_JSON, NULL);
> +
> + close_json_object();
> return 0;
> }
>
> static int ipaddr_showdump(void)
> {
> + int err;
> +
> if (ipadd_dump_check_magic())
> exit(-1);
>
> - exit(rtnl_from_file(stdin, &show_handler, NULL));
> + new_json_obj(json, stdout);
> + err = rtnl_from_file(stdin, &show_handler, NULL);
> + delete_json_obj();
> +
> + exit(err);
> }
>
> static int restore_handler(const struct sockaddr_nl *nl,
> --
> 2.13.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [iproute PATCH v2] ipaddress: Fix segfault in 'addr showdump'
2017-09-13 9:20 [iproute PATCH v2] ipaddress: Fix segfault in 'addr showdump' Phil Sutter
2017-09-15 3:05 ` Julien Fortin
@ 2017-09-21 0:54 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2017-09-21 0:54 UTC (permalink / raw)
To: Phil Sutter; +Cc: Hangbin Liu, netdev, Julien Fortin
On Wed, 13 Sep 2017 11:20:34 +0200
Phil Sutter <phil@nwl.cc> wrote:
> Obviously, 'addr showdump' feature wasn't adjusted to json output
> support. As a consequence, calls to print_string() in print_addrinfo()
> tried to dereference a NULL FILE pointer.
>
> Cc: Julien Fortin <julien@cumulusnetworks.com>
> Fixes: d0e720111aad2 ("ip: ipaddress.c: add support for json output")
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> --
> Changes since v1:
> Align json output with that of 'ip -j addr show':
> - Interface index label is 'ifindex', not 'index' and it doesn't belong
> to 'addr_info' array.
> - Create one 'addr_info' array per dumped address, not one for all.
> ---
> ip/ipaddress.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
Looks good, applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-09-21 0:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-13 9:20 [iproute PATCH v2] ipaddress: Fix segfault in 'addr showdump' Phil Sutter
2017-09-15 3:05 ` Julien Fortin
2017-09-21 0:54 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).