Pino Toscano
2014-Aug-18 18:40 UTC
[Libguestfs] [PATCH] daemon: echo-daemon: do not crash on empty string
When an empty string is passed, then that turns into no elements into the input array, and thus no return buffer is created, leading to dereference null to assign the trailing null. In such situation, create an empty string as return value. --- daemon/echo-daemon.c | 8 ++++++++ generator/actions.ml | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/daemon/echo-daemon.c b/daemon/echo-daemon.c index c805819..d8f1028 100644 --- a/daemon/echo-daemon.c +++ b/daemon/echo-daemon.c @@ -65,6 +65,14 @@ do_echo_daemon (char *const *argv) argv++; } + if (NULL == out) { + /* No strings, so create a new empty array. */ + out = malloc (sizeof (char *)); + if (NULL == out) { + reply_with_perror ("malloc"); + return NULL; + } + } /* NULL terminate the output */ out[out_len] = '\0'; diff --git a/generator/actions.ml b/generator/actions.ml index 9570d9b..bb95f7a 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -7210,7 +7210,9 @@ was built (see C<appliance/kmod.whitelist.in> in the source)." }; proc_nr = Some 195; tests = [ InitNone, Always, TestResultString ( - [["echo_daemon"; "This is a test"]], "This is a test"), [] + [["echo_daemon"; "This is a test"]], "This is a test"), []; + InitNone, Always, TestResultString ( + [["echo_daemon"; ""]], ""), []; ]; shortdesc = "echo arguments back to the client"; longdesc = "\ -- 1.9.3
Richard W.M. Jones
2014-Aug-19 11:17 UTC
Re: [Libguestfs] [PATCH] daemon: echo-daemon: do not crash on empty string
How about this instead? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Seemingly Similar Threads
- [PATCH] Add echo_daemon command
- [PATCH] mkfs: add 'label' optional argument
- [PATCH] tests: disable UUID change on ext journal_dev
- [PATCH 1/2] generator: Simplify the handling of string parameters.
- [PATCH] generator: Allow actions to be deprecated with no replacement.