tools: libxl: NULL terminate partially constructed hex string

Coverity (correctly) complains that the strncpy(p, "0x", 2) will not
null terminate p.

Although we can see that in the rest of the function p will
definitely be NULL terminated by the time it is complete there is no
harm in passing 3 to the strncpy and allowing it to NULL terminate to
placate Coverity. We know this is safe because the allocation to hold
the string includes a "+3" for the 0x and the terminating NULL.

Compile tested only.

CID: 1198708

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
This commit is contained in:
Ian Campbell authored and Ian Jackson committed 2016-02-16 17:38:51 +00:00
1 parent 382c72d83a
commit b021beb21a
1 file changed
+1 -1
+1 -1
View File
@@ -780,7 +780,7 @@ char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *bitmap)
int i = bitmap->size;
char *p = libxl__zalloc(NOGC, bitmap->size * 2 + 3);
char *q = p;
strncpy(p, "0x", 2);
strncpy(p, "0x", 3);
p += 2;
while(--i >= 0) {
sprintf(p, "%02x", bitmap->map[i]);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.