diff options
author | Djalal Harouni <tixxdz@opendz.org> | 2013-08-25 06:50:49 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2013-08-26 14:09:06 -0400 |
commit | 8aada63cc408874916a19341ba514f941096e424 (patch) | |
tree | 6d11d80ff24e0635dbf7092df6b9019a534ea0f6 /drivers/net/wireless/ath/ath5k/debug.c | |
parent | b380a43b52bee70f2e31ed573d33191efd82f5ae (diff) |
ath5k: debugfs: NULL-terminate strings
Avoid processing garbage data by NULL terminating the strings.
Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/ath/ath5k/debug.c')
-rw-r--r-- | drivers/net/wireless/ath/ath5k/debug.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c index 9d00dab666a8..b8d031ae63c2 100644 --- a/drivers/net/wireless/ath/ath5k/debug.c +++ b/drivers/net/wireless/ath/ath5k/debug.c | |||
@@ -245,9 +245,11 @@ static ssize_t write_file_beacon(struct file *file, | |||
245 | struct ath5k_hw *ah = file->private_data; | 245 | struct ath5k_hw *ah = file->private_data; |
246 | char buf[20]; | 246 | char buf[20]; |
247 | 247 | ||
248 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | 248 | count = min_t(size_t, count, sizeof(buf) - 1); |
249 | if (copy_from_user(buf, userbuf, count)) | ||
249 | return -EFAULT; | 250 | return -EFAULT; |
250 | 251 | ||
252 | buf[count] = '\0'; | ||
251 | if (strncmp(buf, "disable", 7) == 0) { | 253 | if (strncmp(buf, "disable", 7) == 0) { |
252 | AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE); | 254 | AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE); |
253 | pr_info("debugfs disable beacons\n"); | 255 | pr_info("debugfs disable beacons\n"); |
@@ -345,9 +347,11 @@ static ssize_t write_file_debug(struct file *file, | |||
345 | unsigned int i; | 347 | unsigned int i; |
346 | char buf[20]; | 348 | char buf[20]; |
347 | 349 | ||
348 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | 350 | count = min_t(size_t, count, sizeof(buf) - 1); |
351 | if (copy_from_user(buf, userbuf, count)) | ||
349 | return -EFAULT; | 352 | return -EFAULT; |
350 | 353 | ||
354 | buf[count] = '\0'; | ||
351 | for (i = 0; i < ARRAY_SIZE(dbg_info); i++) { | 355 | for (i = 0; i < ARRAY_SIZE(dbg_info); i++) { |
352 | if (strncmp(buf, dbg_info[i].name, | 356 | if (strncmp(buf, dbg_info[i].name, |
353 | strlen(dbg_info[i].name)) == 0) { | 357 | strlen(dbg_info[i].name)) == 0) { |
@@ -448,9 +452,11 @@ static ssize_t write_file_antenna(struct file *file, | |||
448 | unsigned int i; | 452 | unsigned int i; |
449 | char buf[20]; | 453 | char buf[20]; |
450 | 454 | ||
451 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | 455 | count = min_t(size_t, count, sizeof(buf) - 1); |
456 | if (copy_from_user(buf, userbuf, count)) | ||
452 | return -EFAULT; | 457 | return -EFAULT; |
453 | 458 | ||
459 | buf[count] = '\0'; | ||
454 | if (strncmp(buf, "diversity", 9) == 0) { | 460 | if (strncmp(buf, "diversity", 9) == 0) { |
455 | ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT); | 461 | ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT); |
456 | pr_info("debug: enable diversity\n"); | 462 | pr_info("debug: enable diversity\n"); |
@@ -619,9 +625,11 @@ static ssize_t write_file_frameerrors(struct file *file, | |||
619 | struct ath5k_statistics *st = &ah->stats; | 625 | struct ath5k_statistics *st = &ah->stats; |
620 | char buf[20]; | 626 | char buf[20]; |
621 | 627 | ||
622 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | 628 | count = min_t(size_t, count, sizeof(buf) - 1); |
629 | if (copy_from_user(buf, userbuf, count)) | ||
623 | return -EFAULT; | 630 | return -EFAULT; |
624 | 631 | ||
632 | buf[count] = '\0'; | ||
625 | if (strncmp(buf, "clear", 5) == 0) { | 633 | if (strncmp(buf, "clear", 5) == 0) { |
626 | st->rxerr_crc = 0; | 634 | st->rxerr_crc = 0; |
627 | st->rxerr_phy = 0; | 635 | st->rxerr_phy = 0; |
@@ -766,9 +774,11 @@ static ssize_t write_file_ani(struct file *file, | |||
766 | struct ath5k_hw *ah = file->private_data; | 774 | struct ath5k_hw *ah = file->private_data; |
767 | char buf[20]; | 775 | char buf[20]; |
768 | 776 | ||
769 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | 777 | count = min_t(size_t, count, sizeof(buf) - 1); |
778 | if (copy_from_user(buf, userbuf, count)) | ||
770 | return -EFAULT; | 779 | return -EFAULT; |
771 | 780 | ||
781 | buf[count] = '\0'; | ||
772 | if (strncmp(buf, "sens-low", 8) == 0) { | 782 | if (strncmp(buf, "sens-low", 8) == 0) { |
773 | ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_HIGH); | 783 | ath5k_ani_init(ah, ATH5K_ANI_MODE_MANUAL_HIGH); |
774 | } else if (strncmp(buf, "sens-high", 9) == 0) { | 784 | } else if (strncmp(buf, "sens-high", 9) == 0) { |
@@ -862,9 +872,11 @@ static ssize_t write_file_queue(struct file *file, | |||
862 | struct ath5k_hw *ah = file->private_data; | 872 | struct ath5k_hw *ah = file->private_data; |
863 | char buf[20]; | 873 | char buf[20]; |
864 | 874 | ||
865 | if (copy_from_user(buf, userbuf, min(count, sizeof(buf)))) | 875 | count = min_t(size_t, count, sizeof(buf) - 1); |
876 | if (copy_from_user(buf, userbuf, count)) | ||
866 | return -EFAULT; | 877 | return -EFAULT; |
867 | 878 | ||
879 | buf[count] = '\0'; | ||
868 | if (strncmp(buf, "start", 5) == 0) | 880 | if (strncmp(buf, "start", 5) == 0) |
869 | ieee80211_wake_queues(ah->hw); | 881 | ieee80211_wake_queues(ah->hw); |
870 | else if (strncmp(buf, "stop", 4) == 0) | 882 | else if (strncmp(buf, "stop", 4) == 0) |