* [PATCH RESEND] apparmor: Replace deprecated strcpy in d_namespace_path
@ 2025-11-06 14:51 Thorsten Blum
2025-11-06 14:54 ` John Johansen
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-11-06 14:51 UTC (permalink / raw)
To: John Johansen, Paul Moore, James Morris, Serge E. Hallyn
Cc: Thorsten Blum, apparmor, linux-security-module, linux-kernel
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.
Link: https://github.com/KSPP/linux/issues/88
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
security/apparmor/path.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/security/apparmor/path.c b/security/apparmor/path.c
index d6c74c357ffd..65a0ca5cc1bd 100644
--- a/security/apparmor/path.c
+++ b/security/apparmor/path.c
@@ -164,12 +164,15 @@ static int d_namespace_path(const struct path *path, char *buf, char **name,
}
out:
- /*
- * Append "/" to the pathname. The root directory is a special
- * case; it already ends in slash.
+ /* Append "/" to directory paths, except for root "/" which
+ * already ends in a slash.
*/
- if (!error && isdir && ((*name)[1] != '\0' || (*name)[0] != '/'))
- strcpy(&buf[aa_g_path_max - 2], "/");
+ if (!error && isdir) {
+ bool is_root = (*name)[0] == '/' && (*name)[1] == '\0';
+
+ if (!is_root)
+ buf[aa_g_path_max - 2] = '/';
+ }
return error;
}
--
2.51.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RESEND] apparmor: Replace deprecated strcpy in d_namespace_path
2025-11-06 14:51 [PATCH RESEND] apparmor: Replace deprecated strcpy in d_namespace_path Thorsten Blum
@ 2025-11-06 14:54 ` John Johansen
0 siblings, 0 replies; 2+ messages in thread
From: John Johansen @ 2025-11-06 14:54 UTC (permalink / raw)
To: Thorsten Blum, Paul Moore, James Morris, Serge E. Hallyn
Cc: apparmor, linux-security-module, linux-kernel
On 11/6/25 06:51, Thorsten Blum wrote:
> 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.
>
> Link: https://github.com/KSPP/linux/issues/88
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
hey Thorsten,
sorry I have just been swamped, and traveling, ...
I will start on the patch backlog tonight
> ---
> security/apparmor/path.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/security/apparmor/path.c b/security/apparmor/path.c
> index d6c74c357ffd..65a0ca5cc1bd 100644
> --- a/security/apparmor/path.c
> +++ b/security/apparmor/path.c
> @@ -164,12 +164,15 @@ static int d_namespace_path(const struct path *path, char *buf, char **name,
> }
>
> out:
> - /*
> - * Append "/" to the pathname. The root directory is a special
> - * case; it already ends in slash.
> + /* Append "/" to directory paths, except for root "/" which
> + * already ends in a slash.
> */
> - if (!error && isdir && ((*name)[1] != '\0' || (*name)[0] != '/'))
> - strcpy(&buf[aa_g_path_max - 2], "/");
> + if (!error && isdir) {
> + bool is_root = (*name)[0] == '/' && (*name)[1] == '\0';
> +
> + if (!is_root)
> + buf[aa_g_path_max - 2] = '/';
> + }
>
> return error;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-06 14:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-06 14:51 [PATCH RESEND] apparmor: Replace deprecated strcpy in d_namespace_path Thorsten Blum
2025-11-06 14:54 ` John Johansen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox