From cd8e5976e05ff2f8588eb3e92bd0ad2308d03183 Mon Sep 17 00:00:00 2001 From: Klaus Kämpf Date: Wed, 20 Apr 2011 12:19:00 +0200 Subject: Fix segfault in wsmancli Using wsmancli 2.2.5, we also got a segmentation fault. Analysis of the code found that output_file is NULL and is being used. This is occurring when there are multiple instances returned and pull operation is done and output file is not defined. Patch by Chris Poblete --- src/wsman.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/wsman.c') diff --git a/src/wsman.c b/src/wsman.c index 51bafb6..75f0c4a 100644 --- a/src/wsman.c +++ b/src/wsman.c @@ -443,15 +443,20 @@ static void wsman_output(WsManClient * cl, WsXmlDocH doc) */ static void wsman_output_pull(WsManClient * cl, WsXmlDocH doc, int index) { - char *strbuf, *origfile = output_file; - int count = strlen(output_file) + 16; - - strbuf = (char*)calloc(count, 1); - snprintf(strbuf, count, "%s-%u.xml", output_file, index); - output_file = strbuf; - wsman_output(cl, doc); - output_file = origfile; - free(strbuf); + char *strbuf, *origfile = output_file; + int count; + + if (output_file) { + count = strlen(output_file) + 16; + strbuf = (char*)calloc(count, 1); + snprintf(strbuf, count, "%s-%u.xml", output_file, index); + output_file = strbuf; + } + wsman_output(cl, doc); + if (origfile) { + output_file = origfile; + free(strbuf); + } } static void initialize_logging(void) -- cgit