]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
apparmor: Replace deprecated strcpy in d_namespace_path
authorThorsten Blum <thorsten.blum@linux.dev>
Thu, 6 Nov 2025 14:51:38 +0000 (15:51 +0100)
committerJohn Johansen <john.johansen@canonical.com>
Sun, 18 Jan 2026 14:53:18 +0000 (06:53 -0800)
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>
security/apparmor/path.c

index d6c74c357ffd595e2cba63818a26ee6048e9a552..65a0ca5cc1bddae56fdec1adc4676a48a03b56a3 100644 (file)
@@ -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;
 }