Skip to content

Commit 1c90ed1

Browse files
tobluxjrjohansen
authored andcommitted
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: KSPP/linux#88 Signed-off-by: Thorsten Blum <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent 00b6765 commit 1c90ed1

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

security/apparmor/apparmorfs.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,16 +1607,20 @@ static char *gen_symlink_name(int depth, const char *dirname, const char *fname)
16071607
{
16081608
char *buffer, *s;
16091609
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;
16111613

1614+
/* Extra 11 bytes: "raw_data" (9) + two slashes "//" (2) */
1615+
size = depth * path_len + strlen(dirname) + strlen(fname) + 11;
16121616
s = buffer = kmalloc(size, GFP_KERNEL);
16131617
if (!buffer)
16141618
return ERR_PTR(-ENOMEM);
16151619

16161620
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;
16201624
}
16211625

16221626
error = snprintf(s, size, "raw_data/%s/%s", dirname, fname);

0 commit comments

Comments
 (0)