[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 07/22] tools/9pfsd: add 9pfs attach request support



On 14.02.24 18:40, Andrew Cooper wrote:
On 08/02/2024 4:55 pm, Juergen Gross wrote:
+static struct p9_fid *alloc_fid_mem(device *device, unsigned int fid,
+                                    const char *path)
+{
+    struct p9_fid *fidp;
+    size_t pathlen;
+
+    pathlen = strlen(path);
+    fidp = calloc(sizeof(*fidp) + pathlen + 1, 1);
+    if ( !fidp )
+        return NULL;
+
+    fidp->fid = fid;
+    strncpy(fidp->path, path, pathlen);
+
+    return fidp;
+}

GitlabCI has something to say about this.
https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1176787593

I think they're all variations of:

io.c: In function 'alloc_fid_mem.isra.8':
io.c:566:5: error: 'strncpy' output truncated before terminating nul
copying as many bytes from a string as its length
[-Werror=stringop-truncation]
      strncpy(fidp->path, path, pathlen);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
io.c:560:15: note: length computed here
      pathlen = strlen(path);
                ^~~~~~~~~~~~

In the end the result is fine, as the buffer is large enough and it is
zeroed on allocation.

I'll change it nevertheless as it is a bad code pattern.


Juergen




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.