Skip to contentSkip to conversation

apparmor: Replace deprecated strcpy in d_namespace_path

PATCH RESEND In review Thorsten Blum 2 participants 2 messages Nov 6, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 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.

---
 security/apparmor/path.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
security/apparmor/path.c +8 -5
index d6c74c357ffd..65a0ca5cc1bd 100644
@@ -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;
 }
Signature · 1 line
2.51.1
maintainer
#1 lore raw
Quoted 8 lines · Thorsten Blum

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.

hey Thorsten,

sorry I have just been swamped, and traveling, ... I will start on the patch backlog tonight

Quoted 29 lines
---
  security/apparmor/path.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
security/apparmor/path.c +8 -5
index d6c74c357ffd..65a0ca5cc1bd 100644
@@ -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;
  }