]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xen/xenbus: Replace strcpy() with memcpy()
authorDavid Laight <david.laight.linux@gmail.com>
Sat, 6 Jun 2026 20:25:58 +0000 (21:25 +0100)
committerJuergen Gross <jgross@suse.com>
Tue, 9 Jun 2026 14:23:41 +0000 (16:23 +0200)
The length of the string is calculated in order to allocate the correct
sized memory block, use the same length to copy the string.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Message-ID: <20260606202633.5018-4-david.laight.linux@gmail.com>

drivers/xen/xenbus/xenbus_probe.c

index eb260eceb4d25d75607f5927060090f7c9d29064..fafb2b84fa5c46ecb684f6ccbded9a17255069a1 100644 (file)
@@ -514,7 +514,7 @@ int xenbus_probe_node(struct xen_bus_type *bus,
        char devname[XEN_BUS_ID_SIZE];
        int err;
        struct xenbus_device *xendev;
-       size_t stringlen;
+       size_t name_len, type_len;
        char *tmpstring;
 
        enum xenbus_state state = xenbus_read_driver_state(NULL, nodename);
@@ -525,8 +525,9 @@ int xenbus_probe_node(struct xen_bus_type *bus,
                return 0;
        }
 
-       stringlen = strlen(nodename) + 1 + strlen(type) + 1;
-       xendev = kzalloc(sizeof(*xendev) + stringlen, GFP_KERNEL);
+       name_len = strlen(nodename);
+       type_len = strlen(type);
+       xendev = kzalloc(sizeof(*xendev) + name_len + 1 + type_len + 1, GFP_KERNEL);
        if (!xendev)
                return -ENOMEM;
 
@@ -535,11 +536,11 @@ int xenbus_probe_node(struct xen_bus_type *bus,
        /* Copy the strings into the extra space. */
 
        tmpstring = (char *)(xendev + 1);
-       strcpy(tmpstring, nodename);
+       memcpy(tmpstring, nodename, name_len);
        xendev->nodename = tmpstring;
 
-       tmpstring += strlen(tmpstring) + 1;
-       strcpy(tmpstring, type);
+       tmpstring += name_len + 1;
+       memcpy(tmpstring, type, type_len);
        xendev->devicetype = tmpstring;
        init_completion(&xendev->down);