Commit 04d604b6 authored by Anisse Astier's avatar Anisse Astier Committed by Will Deacon
Browse files

kvmtool: 9p: fix overapping snprintf

GCC 8.2 gives this warning:

virtio/9p.c: In function ‘virtio_p9_create’:
virtio/9p.c:335:21: error: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
  ret = snprintf(dfid->path, size, "%s/%s", dfid->path, name);
                 ~~~~^~~~~~                 ~~~~~~~~~~

Fix it by allocating a temporary string with dfid->path content instead
of overwriting it in-place, which is limited in glibc snprintf with the
__restrict qualifier.
Reviewed-by: Andre Przywara's avatarAndre Przywara <>
Signed-off-by: default avatarAnisse Astier <>
Signed-off-by: default avatarWill Deacon <>
parent 16509081
......@@ -322,6 +322,7 @@ static void virtio_p9_create(struct p9_dev *p9dev,
struct p9_qid qid;
struct p9_fid *dfid;
char full_path[PATH_MAX];
char *tmp_path;
u32 dfid_val, flags, mode, gid;
virtio_p9_pdu_readf(pdu, "dsddd", &dfid_val,
......@@ -332,7 +333,13 @@ static void virtio_p9_create(struct p9_dev *p9dev,
goto err_out;
size = sizeof(dfid->abs_path) - (dfid->path - dfid->abs_path);
ret = snprintf(dfid->path, size, "%s/%s", dfid->path, name);
tmp_path = strdup(dfid->path);
if (!tmp_path)
goto err_out;
ret = snprintf(dfid->path, size, "%s/%s", tmp_path, name);
if (ret >= (int)size) {
if (size > 0)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment