diff options
author | Helge Deller <deller@gmx.de> | 2014-09-21 16:31:08 -0400 |
---|---|---|
committer | Helge Deller <deller@gmx.de> | 2014-09-21 16:31:08 -0400 |
commit | c735483de1a2cd5d6c6b67bf49cfb2991eae6ea6 (patch) | |
tree | c19e2b034ccd51ca7917ff6b675980ae5ea811ab | |
parent | 94c457deff2a211f8372f69a4d7b0d288183756a (diff) |
parisc: pdc_stable.c: Avoid potential stack overflows
Signed-off-by: Helge Deller <deller@gmx.de>
-rw-r--r-- | drivers/parisc/pdc_stable.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c index e4b73c2a053a..3651c3871d5b 100644 --- a/drivers/parisc/pdc_stable.c +++ b/drivers/parisc/pdc_stable.c | |||
@@ -278,7 +278,7 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t coun | |||
278 | { | 278 | { |
279 | struct hardware_path hwpath; | 279 | struct hardware_path hwpath; |
280 | unsigned short i; | 280 | unsigned short i; |
281 | char in[count+1], *temp; | 281 | char in[64], *temp; |
282 | struct device *dev; | 282 | struct device *dev; |
283 | int ret; | 283 | int ret; |
284 | 284 | ||
@@ -286,8 +286,9 @@ pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t coun | |||
286 | return -EINVAL; | 286 | return -EINVAL; |
287 | 287 | ||
288 | /* We'll use a local copy of buf */ | 288 | /* We'll use a local copy of buf */ |
289 | memset(in, 0, count+1); | 289 | count = min_t(size_t, count, sizeof(in)-1); |
290 | strncpy(in, buf, count); | 290 | strncpy(in, buf, count); |
291 | in[count] = '\0'; | ||
291 | 292 | ||
292 | /* Let's clean up the target. 0xff is a blank pattern */ | 293 | /* Let's clean up the target. 0xff is a blank pattern */ |
293 | memset(&hwpath, 0xff, sizeof(hwpath)); | 294 | memset(&hwpath, 0xff, sizeof(hwpath)); |
@@ -393,14 +394,15 @@ pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count | |||
393 | { | 394 | { |
394 | unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */ | 395 | unsigned int layers[6]; /* device-specific info (ctlr#, unit#, ...) */ |
395 | unsigned short i; | 396 | unsigned short i; |
396 | char in[count+1], *temp; | 397 | char in[64], *temp; |
397 | 398 | ||
398 | if (!entry || !buf || !count) | 399 | if (!entry || !buf || !count) |
399 | return -EINVAL; | 400 | return -EINVAL; |
400 | 401 | ||
401 | /* We'll use a local copy of buf */ | 402 | /* We'll use a local copy of buf */ |
402 | memset(in, 0, count+1); | 403 | count = min_t(size_t, count, sizeof(in)-1); |
403 | strncpy(in, buf, count); | 404 | strncpy(in, buf, count); |
405 | in[count] = '\0'; | ||
404 | 406 | ||
405 | /* Let's clean up the target. 0 is a blank pattern */ | 407 | /* Let's clean up the target. 0 is a blank pattern */ |
406 | memset(&layers, 0, sizeof(layers)); | 408 | memset(&layers, 0, sizeof(layers)); |
@@ -765,7 +767,7 @@ static ssize_t pdcs_auto_write(struct kobject *kobj, | |||
765 | return -EINVAL; | 767 | return -EINVAL; |
766 | 768 | ||
767 | /* We'll use a local copy of buf */ | 769 | /* 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); |
769 | strncpy(in, buf, count); | 771 | strncpy(in, buf, count); |
770 | in[count] = '\0'; | 772 | in[count] = '\0'; |
771 | 773 | ||