diff options
| author | Eric Andersen <andersen@codepoet.org> | 2004-04-05 13:08:08 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2004-04-05 13:08:08 +0000 |
| commit | b2aa776f891b159a2ee8233f44ad70c96b7da86f (patch) | |
| tree | 2e6579fe1f9b9eef8e1af7f079399b23cc47a1f5 /miscutils | |
| parent | 762c64fdf1adea2dcb40d44b7e82f7c7f4c14316 (diff) | |
| download | busybox-w32-b2aa776f891b159a2ee8233f44ad70c96b7da86f.tar.gz busybox-w32-b2aa776f891b159a2ee8233f44ad70c96b7da86f.tar.bz2 busybox-w32-b2aa776f891b159a2ee8233f44ad70c96b7da86f.zip | |
Tito, farmatito at tiscali dot it writes:
Hi to all,
I discovered a little bug in hdparm.c
(really two little bugs...I've made...sigh! Mea culpa).
Some vars were modified only locally and this could lead to wrong
results to be displayed with the -I switch and maybe with others.
Attached is a patch that fix it ( +88b).
Also attached is second patch that reduces the size a little bit:
text data bss dec hex filename
27984 624 900 29508 7344 hdparm.o (without bug-fix)
28072 624 900 29596 739c hdparm.o (with bug-fix)
28141 624 900 29665 73e1 hdparm.o (original)
but maybe this one can wait as we are in a feature freeze.
Ciao,
Tito
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/hdparm.c | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index d0ea6135e..006dc0d49 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c | |||
| @@ -544,20 +544,21 @@ static void sync_and_sleep(int i) | |||
| 544 | sleep(i); | 544 | sleep(i); |
| 545 | } | 545 | } |
| 546 | 546 | ||
| 547 | static void check_if_min_and_set_val(uint16_t a, uint16_t b) | 547 | static uint16_t check_if_min_and_set_val(uint16_t a, uint16_t b) |
| 548 | { | 548 | { |
| 549 | if( a < b) | 549 | if( a < b) |
| 550 | a = b; | 550 | a = b; |
| 551 | return a; | ||
| 551 | } | 552 | } |
| 552 | 553 | ||
| 553 | static void check_if_maj_and_set_val(uint16_t a, uint16_t b) | 554 | static uint16_t check_if_maj_and_set_val(uint16_t a, uint16_t b) |
| 554 | { | 555 | { |
| 555 | if( a > b) | 556 | if( a > b) |
| 556 | a = b; | 557 | a = b; |
| 558 | return a; | ||
| 557 | } | 559 | } |
| 558 | 560 | ||
| 559 | static | 561 | static unsigned long int set_flag(char *p, char max) |
| 560 | unsigned long int set_flag(char *p, char max) | ||
| 561 | { | 562 | { |
| 562 | if (*p >= '0' && *p <= max ) | 563 | if (*p >= '0' && *p <= max ) |
| 563 | return 1; | 564 | return 1; |
| @@ -728,7 +729,7 @@ static void identify (uint16_t *id_supplied, const char *devname) | |||
| 728 | { | 729 | { |
| 729 | if(val[MINOR] && (val[MINOR] <= MINOR_MAX)) | 730 | if(val[MINOR] && (val[MINOR] <= MINOR_MAX)) |
| 730 | { | 731 | { |
| 731 | check_if_min_and_set_val( like_std, 3); | 732 | like_std=check_if_min_and_set_val(like_std, 3); |
| 732 | std = actual_ver[val[MINOR]]; | 733 | std = actual_ver[val[MINOR]]; |
| 733 | if_printf(std,"\n\tUsed: %s ",minor_str[val[MINOR]]); | 734 | if_printf(std,"\n\tUsed: %s ",minor_str[val[MINOR]]); |
| 734 | 735 | ||
| @@ -751,17 +752,17 @@ static void identify (uint16_t *id_supplied, const char *devname) | |||
| 751 | like_std = ii; | 752 | like_std = ii; |
| 752 | kk = like_std >4 ? like_std-4: 0; | 753 | kk = like_std >4 ? like_std-4: 0; |
| 753 | } | 754 | } |
| 754 | check_if_maj_and_set_val(min_std, ii); | 755 | min_std=check_if_maj_and_set_val(min_std, ii); |
| 755 | } | 756 | } |
| 756 | jj <<= 1; | 757 | jj <<= 1; |
| 757 | } | 758 | } |
| 758 | check_if_min_and_set_val( like_std, 3); | 759 | like_std=check_if_min_and_set_val(like_std, 3); |
| 759 | } | 760 | } |
| 760 | /* Figure out what standard the device is using if it hasn't told | 761 | /* Figure out what standard the device is using if it hasn't told |
| 761 | * us. If we know the std, check if the device is using any of | 762 | * us. If we know the std, check if the device is using any of |
| 762 | * the words from the next level up. It happens. | 763 | * the words from the next level up. It happens. |
| 763 | */ | 764 | */ |
| 764 | check_if_min_and_set_val( like_std, std); | 765 | like_std=check_if_min_and_set_val(like_std, std); |
| 765 | 766 | ||
| 766 | if(((std == 5) || (!std && (like_std < 6))) && | 767 | if(((std == 5) || (!std && (like_std < 6))) && |
| 767 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && | 768 | ((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) && |
| @@ -2104,8 +2105,8 @@ static void process_dev (char *devname) | |||
| 2104 | { | 2105 | { |
| 2105 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; | 2106 | unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; |
| 2106 | no_scsi(); | 2107 | no_scsi(); |
| 2107 | check_if_min_and_set_val(apmmode,1); | 2108 | apmmode=check_if_min_and_set_val(apmmode,1); |
| 2108 | check_if_maj_and_set_val(apmmode,255); | 2109 | apmmode=check_if_maj_and_set_val(apmmode,255); |
| 2109 | if_printf(get_apmmode," setting APM level to"); | 2110 | if_printf(get_apmmode," setting APM level to"); |
| 2110 | if (apmmode==255) | 2111 | if (apmmode==255) |
| 2111 | { | 2112 | { |
| @@ -2521,12 +2522,16 @@ static int identify_from_stdin (void) | |||
| 2521 | } | 2522 | } |
| 2522 | #endif | 2523 | #endif |
| 2523 | 2524 | ||
| 2525 | static void missing_arg(int arg, char c, char* add) | ||
| 2526 | { | ||
| 2527 | if (!arg) | ||
| 2528 | bb_error_msg("-%c: missing value %s", c, (add!=NULL)? add :""); | ||
| 2529 | } | ||
| 2530 | |||
| 2524 | /* our main() routine: */ | 2531 | /* our main() routine: */ |
| 2525 | int hdparm_main(int argc, char **argv) | 2532 | int hdparm_main(int argc, char **argv) |
| 2526 | { | 2533 | { |
| 2527 | const char * const bb_msg_missing_value ="missing value"; | ||
| 2528 | char c, *p; | 2534 | char c, *p; |
| 2529 | /*int neg;*/ | ||
| 2530 | 2535 | ||
| 2531 | ++argv; | 2536 | ++argv; |
| 2532 | if (!--argc) | 2537 | if (!--argc) |
| @@ -2638,8 +2643,7 @@ int hdparm_main(int argc, char **argv) | |||
| 2638 | if (!*p && argc && isalnum(**argv)) | 2643 | if (!*p && argc && isalnum(**argv)) |
| 2639 | p = *argv++, --argc; | 2644 | p = *argv++, --argc; |
| 2640 | p=GET_NUMBER(p,&set_standby,&standby_requested); | 2645 | p=GET_NUMBER(p,&set_standby,&standby_requested); |
| 2641 | if (!set_standby) | 2646 | missing_arg(set_standby, c, NULL); |
| 2642 | bb_error_msg("-S: %s", bb_msg_missing_value); | ||
| 2643 | break; | 2647 | break; |
| 2644 | 2648 | ||
| 2645 | case 'D': | 2649 | case 'D': |
| @@ -2648,8 +2652,7 @@ int hdparm_main(int argc, char **argv) | |||
| 2648 | if (!*p && argc && isalnum(**argv)) | 2652 | if (!*p && argc && isalnum(**argv)) |
| 2649 | p = *argv++, --argc; | 2653 | p = *argv++, --argc; |
| 2650 | p=GET_NUMBER(p,&set_defects,&defects); | 2654 | p=GET_NUMBER(p,&set_defects,&defects); |
| 2651 | if (!set_defects) | 2655 | missing_arg(set_defects, c, NULL); |
| 2652 | bb_error_msg("-D: %s", bb_msg_missing_value); | ||
| 2653 | break; | 2656 | break; |
| 2654 | case 'P': | 2657 | case 'P': |
| 2655 | get_prefetch = noisy; | 2658 | get_prefetch = noisy; |
| @@ -2657,8 +2660,7 @@ int hdparm_main(int argc, char **argv) | |||
| 2657 | if (!*p && argc && isalnum(**argv)) | 2660 | if (!*p && argc && isalnum(**argv)) |
| 2658 | p = *argv++, --argc; | 2661 | p = *argv++, --argc; |
| 2659 | p=GET_NUMBER(p,&set_prefetch,&prefetch); | 2662 | p=GET_NUMBER(p,&set_prefetch,&prefetch); |
| 2660 | if (!set_prefetch) | 2663 | missing_arg(set_prefetch, c, NULL); |
| 2661 | bb_error_msg("-P: %s", bb_msg_missing_value); | ||
| 2662 | break; | 2664 | break; |
| 2663 | 2665 | ||
| 2664 | case 'X': | 2666 | case 'X': |
| @@ -2667,8 +2669,7 @@ int hdparm_main(int argc, char **argv) | |||
| 2667 | if (!*p && argc && isalnum(**argv)) | 2669 | if (!*p && argc && isalnum(**argv)) |
| 2668 | p = *argv++, --argc; | 2670 | p = *argv++, --argc; |
| 2669 | p=GET_STRING(p,&set_xfermode,&xfermode_requested); | 2671 | p=GET_STRING(p,&set_xfermode,&xfermode_requested); |
| 2670 | if (!set_xfermode) | 2672 | missing_arg(set_xfermode, c, NULL); |
| 2671 | bb_error_msg("-X: %s", bb_msg_missing_value); | ||
| 2672 | break; | 2673 | break; |
| 2673 | 2674 | ||
| 2674 | case 'K': | 2675 | case 'K': |
| @@ -2679,7 +2680,7 @@ int hdparm_main(int argc, char **argv) | |||
| 2679 | if((set_dkeep = set_flag(p,'1'))==1) | 2680 | if((set_dkeep = set_flag(p,'1'))==1) |
| 2680 | dkeep = *p++ - '0'; | 2681 | dkeep = *p++ - '0'; |
| 2681 | else | 2682 | else |
| 2682 | bb_error_msg("-K: %s (0/1)", bb_msg_missing_value); | 2683 | goto missing_arg_error; |
| 2683 | break; | 2684 | break; |
| 2684 | 2685 | ||
| 2685 | case 'A': | 2686 | case 'A': |
| @@ -2690,7 +2691,7 @@ int hdparm_main(int argc, char **argv) | |||
| 2690 | if((set_lookahead = set_flag(p,'1'))==1) | 2691 | if((set_lookahead = set_flag(p,'1'))==1) |
| 2691 | lookahead = *p++ - '0'; | 2692 | lookahead = *p++ - '0'; |
| 2692 | else | 2693 | else |
| 2693 | bb_error_msg("-A: %s (0/1)", bb_msg_missing_value); | 2694 | goto missing_arg_error; |
| 2694 | break; | 2695 | break; |
| 2695 | 2696 | ||
| 2696 | case 'L': | 2697 | case 'L': |
| @@ -2701,7 +2702,7 @@ int hdparm_main(int argc, char **argv) | |||
| 2701 | if((set_doorlock = set_flag(p,'1'))==1) | 2702 | if((set_doorlock = set_flag(p,'1'))==1) |
| 2702 | doorlock = *p++ - '0'; | 2703 | doorlock = *p++ - '0'; |
| 2703 | else | 2704 | else |
| 2704 | bb_error_msg("-L: %s (0/1)", bb_msg_missing_value); | 2705 | goto missing_arg_error; |
| 2705 | break; | 2706 | break; |
| 2706 | 2707 | ||
| 2707 | case 'W': | 2708 | case 'W': |
| @@ -2712,7 +2713,8 @@ int hdparm_main(int argc, char **argv) | |||
| 2712 | if((set_wcache = set_flag(p,'1'))==1) | 2713 | if((set_wcache = set_flag(p,'1'))==1) |
| 2713 | wcache = *p++ - '0'; | 2714 | wcache = *p++ - '0'; |
| 2714 | else | 2715 | else |
| 2715 | bb_error_msg("-W: %s (0/1)", bb_msg_missing_value); | 2716 | missing_arg_error: |
| 2717 | missing_arg(1, c, "(0/1)"); | ||
| 2716 | break; | 2718 | break; |
| 2717 | 2719 | ||
| 2718 | case 'C': | 2720 | case 'C': |
| @@ -2755,7 +2757,7 @@ int hdparm_main(int argc, char **argv) | |||
| 2755 | if (!*p && argc && isdigit(**argv)) | 2757 | if (!*p && argc && isdigit(**argv)) |
| 2756 | p = *argv++, --argc; | 2758 | p = *argv++, --argc; |
| 2757 | if(! p) | 2759 | if(! p) |
| 2758 | goto error; /* "expected hwif_nr" */ | 2760 | goto expected_hwif_error; /* "expected hwif_nr" */ |
| 2759 | 2761 | ||
| 2760 | sscanf(p++, "%i", &hwif); | 2762 | sscanf(p++, "%i", &hwif); |
| 2761 | 2763 | ||
| @@ -2767,21 +2769,21 @@ int hdparm_main(int argc, char **argv) | |||
| 2767 | if (!*p && argc && isdigit(**argv)) | 2769 | if (!*p && argc && isdigit(**argv)) |
| 2768 | p = *argv++, --argc; | 2770 | p = *argv++, --argc; |
| 2769 | if(! p) | 2771 | if(! p) |
| 2770 | goto error; /* "expected hwif_data" */ | 2772 | goto expected_hwif_error; /* "expected hwif_data" */ |
| 2771 | 2773 | ||
| 2772 | sscanf(p++, "%i", &hwif_data); | 2774 | sscanf(p++, "%i", &hwif_data); |
| 2773 | 2775 | ||
| 2774 | if (argc && isdigit(**argv)) | 2776 | if (argc && isdigit(**argv)) |
| 2775 | p = *argv++, --argc; | 2777 | p = *argv++, --argc; |
| 2776 | else | 2778 | else |
| 2777 | goto error; /* "expected hwif_ctrl" */ | 2779 | goto expected_hwif_error; /* "expected hwif_ctrl" */ |
| 2778 | 2780 | ||
| 2779 | sscanf(p, "%i", &hwif_ctrl); | 2781 | sscanf(p, "%i", &hwif_ctrl); |
| 2780 | 2782 | ||
| 2781 | if (argc && isdigit(**argv)) | 2783 | if (argc && isdigit(**argv)) |
| 2782 | p = *argv++, --argc; | 2784 | p = *argv++, --argc; |
| 2783 | else | 2785 | else |
| 2784 | error: | 2786 | expected_hwif_error: |
| 2785 | bb_error_msg_and_die("expected hwif value"); /* "expected hwif_irq" */ | 2787 | bb_error_msg_and_die("expected hwif value"); /* "expected hwif_irq" */ |
| 2786 | 2788 | ||
| 2787 | sscanf(p, "%i", &hwif_irq); | 2789 | sscanf(p, "%i", &hwif_irq); |
| @@ -2818,7 +2820,7 @@ error: | |||
| 2818 | if((perform_tristate = set_flag(p,'1'))==1) | 2820 | if((perform_tristate = set_flag(p,'1'))==1) |
| 2819 | tristate = *p++ - '0'; | 2821 | tristate = *p++ - '0'; |
| 2820 | else | 2822 | else |
| 2821 | bb_error_msg("-x: %s (0/1)", bb_msg_missing_value); | 2823 | missing_arg(1, c, "(0/1)"); |
| 2822 | break; | 2824 | break; |
| 2823 | 2825 | ||
| 2824 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ | 2826 | #endif /* CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ |
| @@ -2835,8 +2837,7 @@ error: | |||
| 2835 | if (!*p && argc && isalnum(**argv)) | 2837 | if (!*p && argc && isalnum(**argv)) |
| 2836 | p = *argv++, --argc; | 2838 | p = *argv++, --argc; |
| 2837 | p=GET_NUMBER(p,&set_apmmode,&apmmode); | 2839 | p=GET_NUMBER(p,&set_apmmode,&apmmode); |
| 2838 | if (!set_apmmode) | 2840 | missing_arg(set_apmmode, c, "(1-255)"); |
| 2839 | bb_error_msg("-B: %s (1-255)", bb_msg_missing_value); | ||
| 2840 | break; | 2841 | break; |
| 2841 | case 't': | 2842 | case 't': |
| 2842 | do_timings = 1; | 2843 | do_timings = 1; |
