]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
tools/xenstored: Avoid unnecessary talloc_strdup() in do_lu_start()
authorJulien Grall <jgrall@amazon.com>
Thu, 25 Feb 2021 15:43:04 +0000 (15:43 +0000)
committerJulien Grall <jgrall@amazon.com>
Fri, 26 Feb 2021 09:45:58 +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: af216a99fb4a ("tools/xenstore: add the basic framework for doing the live update")
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 e8a501acdb62d264942a9898de6b56ce6b2ea574..8eb57827765cffee585846a18cf4a29ff75d6411 100644 (file)
@@ -638,7 +638,6 @@ static bool do_lu_start(struct delayed_request *req)
 {
        time_t now = time(NULL);
        const char *ret;
-       char *resp;
 
        if (!lu_check_lu_allowed()) {
                if (now < lu_status->started_at + lu_status->timeout)
@@ -660,8 +659,7 @@ static bool do_lu_start(struct delayed_request *req)
  out:
        talloc_free(lu_status);
 
-       resp = talloc_strdup(req->in, ret);
-       send_reply(lu_status->conn, XS_CONTROL, resp, strlen(resp) + 1);
+       send_reply(lu_status->conn, XS_CONTROL, ret, strlen(ret) + 1);
 
        return true;
 }