Skip to content

Commit 93d4dbd

Browse files
tobluxjrjohansen
authored andcommitted
apparmor: Replace deprecated strcpy in d_namespace_path
strcpy() is deprecated; replace it with a direct '/' assignment. The buffer is already NUL-terminated, so there is no need to copy an additional NUL terminator as strcpy() did. Update the comment and add the local variable 'is_root' for clarity. Closes: KSPP/linux#88 Signed-off-by: Thorsten Blum <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent b31d3f7 commit 93d4dbd

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

security/apparmor/path.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,15 @@ static int d_namespace_path(const struct path *path, char *buf, char **name,
164164
}
165165

166166
out:
167-
/*
168-
* Append "/" to the pathname. The root directory is a special
169-
* case; it already ends in slash.
167+
/* Append "/" to directory paths, except for root "/" which
168+
* already ends in a slash.
170169
*/
171-
if (!error && isdir && ((*name)[1] != '\0' || (*name)[0] != '/'))
172-
strcpy(&buf[aa_g_path_max - 2], "/");
170+
if (!error && isdir) {
171+
bool is_root = (*name)[0] == '/' && (*name)[1] == '\0';
172+
173+
if (!is_root)
174+
buf[aa_g_path_max - 2] = '/';
175+
}
173176

174177
return error;
175178
}

0 commit comments

Comments
 (0)