diff options
author | Klaus Kämpf <kkaempf@suse.de> | 2011-04-20 12:19:00 +0200 |
---|---|---|
committer | Klaus Kämpf <kkaempf@suse.de> | 2011-04-20 12:19:00 +0200 |
commit | cd8e5976e05ff2f8588eb3e92bd0ad2308d03183 (patch) | |
tree | 3714a9ccca5a6722e2382c54731fba4c7f66acab | |
parent | d9e9961202804c5b29bfc583f9a0676cdf7a71da (diff) | |
download | wsmancli-cd8e5976e05ff2f8588eb3e92bd0ad2308d03183.tar.gz wsmancli-cd8e5976e05ff2f8588eb3e92bd0ad2308d03183.tar.xz wsmancli-cd8e5976e05ff2f8588eb3e92bd0ad2308d03183.zip |
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
-rw-r--r-- | src/wsman.c | 23 |
1 files changed, 14 insertions, 9 deletions
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) |