Skip to contentSkip to conversation

kcsan: test: Replace deprecated strcpy() with strscpy()

PATCH In review Thorsten Blum 3 participants 4 messages Aug 15, 2025 – Aug 19, 2025 KCSAN

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kcsan: test: Replace deprecated strcpy() with strscpy()

strcpy() is deprecated; use strscpy() instead.

---
 kernel/kcsan/kcsan_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kcsan/kcsan_test.c +2 -2
index 49ab81faaed9..ea1cb4c8a894 100644
@@ -125,7 +125,7 @@ static void probe_console(void *ignore, const char *buf, size_t len)
 				goto out;
 
 			/* No second line of interest. */
-			strcpy(observed.lines[nlines++], "<none>");
+			strscpy(observed.lines[nlines++], "<none>");
 		}
 	}
 
@@ -231,7 +231,7 @@ static bool __report_matches(const struct expect_report *r)
 
 			if (!r->access[1].fn) {
 				/* Dummy string if no second access is available. */
-				strcpy(cur, "<none>");
+				strscpy(expect[2], "<none>");
 				break;
 			}
 		}
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 13 lines · Thorsten Blum

strcpy() is deprecated; use strscpy() instead.

---
 kernel/kcsan/kcsan_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kcsan/kcsan_test.c +0 -0
index 49ab81faaed9..ea1cb4c8a894 100644

kernel/kcsan/kcsan_test.c static void probe_console(void *ignore, const char *buf, size_t len) · line 128

Quoted 5 lines
kernel/kcsan/kcsan_test.c +1 -1
@@ -125,7 +125,7 @@ static void probe_console(void *ignore, const char *buf, size_t len)
 				goto out;
 
 			/* No second line of interest. */
-			strcpy(observed.lines[nlines++], "<none>");
+			strscpy(observed.lines[nlines++], "<none>");

Looks good.

Here's my checklist:
1) strcpy() and strscpy() have differing return values, but we aren't using it.
2) strscpy() can fail with -E2BIG if source is too big, but it isn't in this case.
3) two-arg version of strscpy() is OK to use here as the source has a known size at compile time.

Quoted 16 lines
kernel/kcsan/kcsan_test.c +1 -1
 		}
 	}
 
@@ -231,7 +231,7 @@ static bool __report_matches(const struct expect_report *r)
 
 			if (!r->access[1].fn) {
 				/* Dummy string if no second access is available. */
-				strcpy(cur, "<none>");
+				strscpy(expect[2], "<none>");
 				break;
 			}
 		}
Signature · 1 line
2.50.1

Thanks
Justin

#2 lore raw
Quoted 11 lines · Justin Stitt

Looks good.

Here's my checklist:
1) strcpy() and strscpy() have differing return values, but we aren't using it.
2) strscpy() can fail with -E2BIG if source is too big, but it isn't in this case.
3) two-arg version of strscpy() is OK to use here as the source has a known size at compile time.

Thanks for your thorough review.

Thorsten

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Thorsten Blum
Quoted 5 lines · Thorsten Blum

strcpy() is deprecated; use strscpy() instead.

Taking this into the -kcsan tree, but might be a while until it hits mainline.

Quoted 33 lines
---
 kernel/kcsan/kcsan_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kcsan/kcsan_test.c +2 -3
index 49ab81faaed9..ea1cb4c8a894 100644
@@ -125,7 +125,7 @@ static void probe_console(void *ignore, const char *buf, size_t len)
                                goto out;
 
                        /* No second line of interest. */
-                       strcpy(observed.lines[nlines++], "<none>");
+                       strscpy(observed.lines[nlines++], "<none>");
                }
        }
 
@@ -231,7 +231,7 @@ static bool __report_matches(const struct expect_report *r)
 
                        if (!r->access[1].fn) {
                                /* Dummy string if no second access is available. */
-                               strcpy(cur, "<none>");
+                               strscpy(expect[2], "<none>");
                                break;
                        }
                }
--

2.50.1

--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/kasan-dev/20250815213742.321911-3-thorsten.blum%40linux.dev.