Skip to content

Commit

Permalink
confile_utils: fix overlapping strncpy
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
flx42 committed Nov 22, 2017
1 parent ba715de commit ee3e84d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lxc/confile_utils.c
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit ee3e84d

Please sign in to comment.