From db7c85284f7a1c472da0e905a0020ed02d37f539 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 18 Nov 2015 15:36:04 -0800 Subject: Quagga: Fixup cli and json keyword The json keyword was being read incorrectly. Basically some commands read a variable # of arguments and in ospf the command values were being placed into argc and argv. With a variable # of arguments their existed a possibility that less arguments would be read from the cli than were being tested for in the command function handler. This caused core dumps in some situations. All code to read to decide to use the json keyword has been centralized through a function and all code converted to use it, irrelevant if it exhibited the bug Ticket: CM-8278 Reviewed by: CCR-3830 Testing: OSPF no longer crashes and all other test suites still run Signed-off-by: Donald Sharp --- lib/json.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/json.c') diff --git a/lib/json.c b/lib/json.c index 07b70e4f06..f78bfcd844 100644 --- a/lib/json.c +++ b/lib/json.c @@ -19,8 +19,26 @@ * 02111-1307, USA. */ +#include #include "lib/json.h" +/* + * This function assumes that the json keyword + * is the *last* keyword on the line no matter + * what. + */ +int +use_json (const int argc, const char *argv[]) +{ + if (argc == 0) + return 0; + + if (argv[argc-1] && strcmp(argv[argc-1], "json") == 0) + return 1; + + return 0; +} + void json_object_string_add(struct json_object* obj, const char *key, const char *s) -- cgit v1.2.3