Skip to contentSkip to conversation

powerpc: replace strlcat to simplify ppc_kallsyms_lookup_name

PATCH In review Thorsten Blum 2 participants 2 messages Jun 8 – Jun 9 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: replace strlcat to simplify ppc_kallsyms_lookup_name

strlcat() should not be used anymore (see fortify-string.h), and since name is guaranteed to be NUL-terminated within KSYM_NAME_LEN bytes, use memcpy() instead.

Rename dot_appended to the semantically clearer prepend_dot while at it.

---
 arch/powerpc/include/asm/text-patching.h | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/text-patching.h +8 -9
index e7f14720f630..c47b813bd067 100644
@@ -227,22 +227,21 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name)
 #ifdef CONFIG_PPC64_ELF_ABI_V1
 	/* check for dot variant */
 	char dot_name[1 + KSYM_NAME_LEN];
-	bool dot_appended = false;
+	bool prepend_dot = name[0] != '.';
+	size_t len = strnlen(name, KSYM_NAME_LEN);
 
-	if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN)
+	if (len == KSYM_NAME_LEN)
 		return 0;
 
-	if (name[0] != '.') {
+	if (prepend_dot) {
 		dot_name[0] = '.';
-		dot_name[1] = '\0';
-		strlcat(dot_name, name, sizeof(dot_name));
-		dot_appended = true;
+		memcpy(dot_name + 1, name, len + 1);
 	} else {
-		dot_name[0] = '\0';
-		strlcat(dot_name, name, sizeof(dot_name));
+		memcpy(dot_name, name, len + 1);
 	}
+
 	addr = kallsyms_lookup_name(dot_name);
-	if (!addr && dot_appended)
+	if (!addr && prepend_dot)
 		/* Let's try the original non-dot symbol lookup	*/
 		addr = kallsyms_lookup_name(name);
 #elif defined(CONFIG_PPC64_ELF_ABI_V2)
#1 lore raw

Le 08/06/2026 à 21:32, Thorsten Blum a écrit :

Quoted 7 lines

strlcat() should not be used anymore (see fortify-string.h), and since name is guaranteed to be NUL-terminated within KSYM_NAME_LEN bytes, use memcpy() instead.

Rename dot_appended to the semantically clearer prepend_dot while at it.

Please take https://patchwork.ozlabs.org/project/linuxppc-dev/patch/[email protected]/ instead

Christophe

Quoted 39 lines
---
  arch/powerpc/include/asm/text-patching.h | 17 ++++++++---------
  1 file changed, 8 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/text-patching.h +8 -9
index e7f14720f630..c47b813bd067 100644
@@ -227,22 +227,21 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name)
  #ifdef CONFIG_PPC64_ELF_ABI_V1
  	/* check for dot variant */
  	char dot_name[1 + KSYM_NAME_LEN];
-	bool dot_appended = false;
+	bool prepend_dot = name[0] != '.';
+	size_t len = strnlen(name, KSYM_NAME_LEN);
 
-	if (strnlen(name, KSYM_NAME_LEN) >= KSYM_NAME_LEN)
+	if (len == KSYM_NAME_LEN)
  		return 0;
 
-	if (name[0] != '.') {
+	if (prepend_dot) {
  		dot_name[0] = '.';
-		dot_name[1] = '\0';
-		strlcat(dot_name, name, sizeof(dot_name));
-		dot_appended = true;
+		memcpy(dot_name + 1, name, len + 1);
  	} else {
-		dot_name[0] = '\0';
-		strlcat(dot_name, name, sizeof(dot_name));
+		memcpy(dot_name, name, len + 1);
  	}
+
  	addr = kallsyms_lookup_name(dot_name);
-	if (!addr && dot_appended)
+	if (!addr && prepend_dot)
  		/* Let's try the original non-dot symbol lookup	*/
  		addr = kallsyms_lookup_name(name);
  #elif defined(CONFIG_PPC64_ELF_ABI_V2)