]> git.proxmox.com Git - mirror_lxc.git/commitdiff
confile_utils: fix overlapping strncpy
authorFelix Abecassis <fabecassis@nvidia.com>
Wed, 22 Nov 2017 06:27:19 +0000 (22:27 -0800)
committerFelix Abecassis <fabecassis@nvidia.com>
Wed, 22 Nov 2017 06:33:01 +0000 (22:33 -0800)
In the case of "lxc.net.0.type", the pointers passed to strncpy were
only 2 elements apart, resulting in undefined behavior.

Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
src/lxc/confile_utils.c

index d86a2d88edded0815ddd1dcbc8907b640a60a8ae..50f42ef8c482e4507c0cf45fab6cf320be6c72f4 100644 (file)
@@ -567,7 +567,8 @@ bool lxc_config_net_hwaddr(const char *line)
                        return false;
                }
                /* strlen("hwaddr") = 6 */
-               strncpy(copy + 8, p + 1, 6);
+               if (strlen(p + 1) >= 6)
+                        memmove(copy + 8, p + 1, 6);
                copy[8 + 6] = '\0';
        }
        if (strncmp(copy, "lxc.net.hwaddr", 14) == 0) {
@@ -591,7 +592,8 @@ bool lxc_config_net_hwaddr(const char *line)
                        return false;
                }
                /* strlen("hwaddr") = 6 */
-               strncpy(copy + 12, p + 1, 6);
+               if (strlen(p + 1) >= 6)
+                       memmove(copy + 12, p + 1, 6);
                copy[12 + 6] = '\0';
        }
        if (strncmp(copy, "lxc.network.hwaddr", 18) == 0) {