]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile_utils: fix overlapping strncpy
authorFelix Abecassis <fabecassis@nvidia.com>
Wed, 22 Nov 2017 06:27:19 +0000 (22:27 -0800)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 Dec 2017 11:15:37 +0000 (12:15 +0100)
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 af8946a8d2142f649ef90d32536c236d2ef79e25..912deb36f665357d981db1ec53ee4872d668cd78 100644 (file)
@@ -568,7 +568,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) {
@@ -592,7 +593,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) {