]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
tools/xenstored: Avoid unnecessary talloc_strdup() in do_control_lu()
authorJulien Grall <jgrall@amazon.com>
Thu, 25 Feb 2021 15:15:23 +0000 (15:15 +0000)
committerJulien Grall <jgrall@amazon.com>
Fri, 26 Feb 2021 09:45:41 +0000 (09:45 +0000)
At the moment, the return of talloc_strdup() is not checked. This means
we may dereference a NULL pointer if the allocation failed.

However, it is pointless to allocate the memory as send_reply() will
copy the data to a different buffer. So drop the use of talloc_strdup().

This bug was discovered and resolved using Coverity Static Analysis
Security Testing (SAST) by Synopsys, Inc.

Fixes: fecab256d474 ("tools/xenstore: add basic live-update command parsing")
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
tools/xenstore/xenstored_control.c

index f10beaf85eb49ce8102d52d406f096e8a3c8a44e..e8a501acdb62d264942a9898de6b56ce6b2ea574 100644 (file)
@@ -691,7 +691,6 @@ static const char *lu_start(const void *ctx, struct connection *conn,
 static int do_control_lu(void *ctx, struct connection *conn,
                         char **vec, int num)
 {
-       const char *resp;
        const char *ret = NULL;
        unsigned int i;
        bool force = false;
@@ -734,8 +733,7 @@ static int do_control_lu(void *ctx, struct connection *conn,
 
        if (!ret)
                ret = "OK";
-       resp = talloc_strdup(ctx, ret);
-       send_reply(conn, XS_CONTROL, resp, strlen(resp) + 1);
+       send_reply(conn, XS_CONTROL, ret, strlen(ret) + 1);
        return 0;
 }
 #endif