Skip to content

Commit

Permalink
parisc: pdc_stable.c: Avoid potential stack overflows
Browse files Browse the repository at this point in the history
Signed-off-by: Helge Deller <[email protected]>
  • Loading branch information
hdeller committed Sep 21, 2014
1 parent 94c457d commit c735483
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/parisc/pdc_stable.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,17 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t coun
{
struct hardware_path hwpath;
unsigned short i;
char in[count+1], *temp;
char in[64], *temp;
struct device *dev;
int ret;

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

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

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

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

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

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

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

Expand Down

0 comments on commit c735483

Please sign in to comment.