Skip to content

Commit f2193bb

Browse files
Xu Pandahdeller
authored andcommitted
parisc: pdc_stable: use strscpy() to instead of strncpy()
The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL-terminated strings. Signed-off-by: Xu Panda <[email protected]> Signed-off-by: Yang Yang <[email protected]> Signed-off-by: Helge Deller <[email protected]>
1 parent b7bfaa7 commit f2193bb

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

drivers/parisc/pdc_stable.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t coun
274274

275275
/* We'll use a local copy of buf */
276276
count = min_t(size_t, count, sizeof(in)-1);
277-
strncpy(in, buf, count);
278-
in[count] = '\0';
277+
strscpy(in, buf, count + 1);
279278

280279
/* Let's clean up the target. 0xff is a blank pattern */
281280
memset(&hwpath, 0xff, sizeof(hwpath));
@@ -388,8 +387,7 @@ pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count
388387

389388
/* We'll use a local copy of buf */
390389
count = min_t(size_t, count, sizeof(in)-1);
391-
strncpy(in, buf, count);
392-
in[count] = '\0';
390+
strscpy(in, buf, count + 1);
393391

394392
/* Let's clean up the target. 0 is a blank pattern */
395393
memset(&layers, 0, sizeof(layers));
@@ -756,8 +754,7 @@ static ssize_t pdcs_auto_write(struct kobject *kobj,
756754

757755
/* We'll use a local copy of buf */
758756
count = min_t(size_t, count, sizeof(in)-1);
759-
strncpy(in, buf, count);
760-
in[count] = '\0';
757+
strscpy(in, buf, count + 1);
761758

762759
/* Current flags are stored in primary boot path entry */
763760
pathentry = &pdcspath_entry_primary;

0 commit comments

Comments
 (0)