{"id":813251,"url":"http://patchwork.ozlabs.org/api/1.2/patches/813251/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/20170913092034.7002-1-phil@nwl.cc/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.2/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170913092034.7002-1-phil@nwl.cc>","list_archive_url":null,"date":"2017-09-13T09:20:34","name":"[iproute,v2] ipaddress: Fix segfault in 'addr showdump'","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"c03472d61de3e71832df6418073b0937c6ee692e","submitter":{"id":4285,"url":"http://patchwork.ozlabs.org/api/1.2/people/4285/?format=json","name":"Phil Sutter","email":"phil@nwl.cc"},"delegate":{"id":389,"url":"http://patchwork.ozlabs.org/api/1.2/users/389/?format=json","username":"shemminger","first_name":"stephen","last_name":"hemminger","email":"shemminger@vyatta.com"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20170913092034.7002-1-phil@nwl.cc/mbox/","series":[{"id":2848,"url":"http://patchwork.ozlabs.org/api/1.2/series/2848/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=2848","date":"2017-09-13T09:20:34","name":"[iproute,v2] ipaddress: Fix segfault in 'addr showdump'","version":2,"mbox":"http://patchwork.ozlabs.org/series/2848/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/813251/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/813251/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xsbk95nk0z9sPs\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed, 13 Sep 2017 19:20:49 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752090AbdIMJUr (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tWed, 13 Sep 2017 05:20:47 -0400","from orbyte.nwl.cc ([151.80.46.58]:50188 \"EHLO orbyte.nwl.cc\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1751507AbdIMJUq (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tWed, 13 Sep 2017 05:20:46 -0400","from localhost ([::1]:44730 helo=xsao)\n\tby orbyte.nwl.cc with esmtp (Exim 4.89)\n\t(envelope-from <phil@nwl.cc>)\n\tid 1ds3qe-0006vQ-Nf; Wed, 13 Sep 2017 11:20:44 +0200"],"From":"Phil Sutter <phil@nwl.cc>","To":"Stephen Hemminger <stephen@networkplumber.org>","Cc":"Hangbin Liu <liuhangbin@gmail.com>, netdev@vger.kernel.org,\n\tJulien Fortin <julien@cumulusnetworks.com>","Subject":"[iproute PATCH v2] ipaddress: Fix segfault in 'addr showdump'","Date":"Wed, 13 Sep 2017 11:20:34 +0200","Message-Id":"<20170913092034.7002-1-phil@nwl.cc>","X-Mailer":"git-send-email 2.13.1","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"Obviously, 'addr showdump' feature wasn't adjusted to json output\nsupport. As a consequence, calls to print_string() in print_addrinfo()\ntried to dereference a NULL FILE pointer.\n\nCc: Julien Fortin <julien@cumulusnetworks.com>\nFixes: d0e720111aad2 (\"ip: ipaddress.c: add support for json output\")\nSigned-off-by: Phil Sutter <phil@nwl.cc>\n--\nChanges since v1:\nAlign json output with that of 'ip -j addr show':\n- Interface index label is 'ifindex', not 'index' and it doesn't belong\n  to 'addr_info' array.\n- Create one 'addr_info' array per dumped address, not one for all.\n---\n ip/ipaddress.c | 20 ++++++++++++++++++--\n 1 file changed, 18 insertions(+), 2 deletions(-)","diff":"diff --git a/ip/ipaddress.c b/ip/ipaddress.c\nindex 9797145023966..4c47809570410 100644\n--- a/ip/ipaddress.c\n+++ b/ip/ipaddress.c\n@@ -1801,17 +1801,33 @@ static int show_handler(const struct sockaddr_nl *nl,\n {\n \tstruct ifaddrmsg *ifa = NLMSG_DATA(n);\n \n-\tprintf(\"if%d:\\n\", ifa->ifa_index);\n+\topen_json_object(NULL);\n+\tprint_int(PRINT_ANY, \"ifindex\", \"if%d:\\n\", ifa->ifa_index);\n+\n+\topen_json_array(PRINT_JSON, \"addr_info\");\n+\topen_json_object(NULL);\n+\n \tprint_addrinfo(NULL, n, stdout);\n+\n+\tclose_json_object();\n+\tclose_json_array(PRINT_JSON, NULL);\n+\n+\tclose_json_object();\n \treturn 0;\n }\n \n static int ipaddr_showdump(void)\n {\n+\tint err;\n+\n \tif (ipadd_dump_check_magic())\n \t\texit(-1);\n \n-\texit(rtnl_from_file(stdin, &show_handler, NULL));\n+\tnew_json_obj(json, stdout);\n+\terr = rtnl_from_file(stdin, &show_handler, NULL);\n+\tdelete_json_obj();\n+\n+\texit(err);\n }\n \n static int restore_handler(const struct sockaddr_nl *nl,\n","prefixes":["iproute","v2"]}