Skip to content

Commit c735483

Browse files
committed
parisc: pdc_stable.c: Avoid potential stack overflows
Signed-off-by: Helge Deller <deller@gmx.de>
1 parent 94c457d commit c735483

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎drivers/parisc/pdc_stable.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,17 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t coun
278278
{
279279
struct hardware_path hwpath;
280280
unsigned short i;
281-
char in[count+1], *temp;
281+
char in[64], *temp;
282282
struct device *dev;
283283
int ret;
284284

285285
if (!entry || !buf || !count)
286286
return -EINVAL;
287287

288288
/* We'll use a local copy of buf */
289-
memset(in, 0, count+1);
289+
count = min_t(size_t, count, sizeof(in)-1);
290290
strncpy(in, buf, count);
291+
in[count] = '\0';
291292

292293
/* Let's clean up the target. 0xff is a blank pattern */
293294
memset(&hwpath, 0xff, sizeof(hwpath));
@@ -393,14 +394,15 @@ pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count
393394
{
394395
unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */
395396
unsigned short i;
396-
char in[count+1], *temp;
397+
char in[64], *temp;
397398

398399
if (!entry || !buf || !count)
399400
return -EINVAL;
400401

401402
/* We'll use a local copy of buf */
402-
memset(in, 0, count+1);
403+
count = min_t(size_t, count, sizeof(in)-1);
403404
strncpy(in, buf, count);
405+
in[count] = '\0';
404406

405407
/* Let's clean up the target. 0 is a blank pattern */
406408
memset(&layers, 0, sizeof(layers));
@@ -765,7 +767,7 @@ static ssize_t pdcs_auto_write(struct kobject *kobj,
765767
return -EINVAL;
766768

767769
/* We'll use a local copy of buf */
768-
count = min_t(size_t, count, 7);
770+
count = min_t(size_t, count, sizeof(in)-1);
769771
strncpy(in, buf, count);
770772
in[count] = '\0';
771773

0 commit comments

Comments
 (0)