Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

apparmor: Replace deprecated strcpy with memcpy in gen_symlink_name

strcpy() is deprecated; use memcpy() instead. Unlike strcpy(), memcpy()
does not copy the NUL terminator from the source string, which would be
overwritten anyway on every iteration when using strcpy(). snprintf()
then ensures that 'char *s' is NUL-terminated.

Replace the hard-coded path length to remove the magic number 6, and add
a comment explaining the extra 11 bytes.

Closes: https://github.com/KSPP/linux/issues/88
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: John Johansen <john.johansen@canonical.com>

authored by

Thorsten Blum and committed by
John Johansen
1c90ed1f 00b67657

+8 -4
+8 -4
security/apparmor/apparmorfs.c
··· 1607 1607 { 1608 1608 char *buffer, *s; 1609 1609 int error; 1610 - int size = depth * 6 + strlen(dirname) + strlen(fname) + 11; 1610 + const char *path = "../../"; 1611 + size_t path_len = strlen(path); 1612 + int size; 1611 1613 1614 + /* Extra 11 bytes: "raw_data" (9) + two slashes "//" (2) */ 1615 + size = depth * path_len + strlen(dirname) + strlen(fname) + 11; 1612 1616 s = buffer = kmalloc(size, GFP_KERNEL); 1613 1617 if (!buffer) 1614 1618 return ERR_PTR(-ENOMEM); 1615 1619 1616 1620 for (; depth > 0; depth--) { 1617 - strcpy(s, "../../"); 1618 - s += 6; 1619 - size -= 6; 1621 + memcpy(s, path, path_len); 1622 + s += path_len; 1623 + size -= path_len; 1620 1624 } 1621 1625 1622 1626 error = snprintf(s, size, "raw_data/%s/%s", dirname, fname);