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: 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>
This commit is contained in:
Thorsten Blum
2026-01-18 06:53:18 -08:00
committed by John Johansen
parent b31d3f7385
commit 93d4dbdc8d
+8 -5
View File
@@ -164,12 +164,15 @@ static int d_namespace_path(const struct path *path, char *buf, char **name,
} }
out: out:
/* /* Append "/" to directory paths, except for root "/" which
* Append "/" to the pathname. The root directory is a special * already ends in a slash.
* case; it already ends in slash.
*/ */
if (!error && isdir && ((*name)[1] != '\0' || (*name)[0] != '/')) if (!error && isdir) {
strcpy(&buf[aa_g_path_max - 2], "/"); bool is_root = (*name)[0] == '/' && (*name)[1] == '\0';
if (!is_root)
buf[aa_g_path_max - 2] = '/';
}
return error; return error;
} }