Author: avg Date: Mon Oct 12 11:04:52 2020 New Revision: 366643 URL: https://svnweb.freebsd.org/changeset/base/366643
Log: MFC r366144: pwm(8): fix potential duty overflow, use unsigneds for period and duty Modified: stable/12/usr.sbin/pwm/pwm.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.sbin/pwm/pwm.c ============================================================================== --- stable/12/usr.sbin/pwm/pwm.c Mon Oct 12 11:03:26 2020 (r366642) +++ stable/12/usr.sbin/pwm/pwm.c Mon Oct 12 11:04:52 2020 (r366643) @@ -76,7 +76,7 @@ main(int argc, char *argv[]) { struct pwm_state state; int fd; - int period, duty; + u_int period, duty; int action, ch; cap_rights_t right_ioctl; const unsigned long pwm_ioctls[] = {PWMGETSTATE, PWMSETSTATE}; @@ -109,16 +109,16 @@ main(int argc, char *argv[]) if (action & PWM_SHOW_CONFIG) usage(); action |= PWM_PERIOD; - period = strtol(optarg, NULL, 10); + period = strtoul(optarg, NULL, 10); break; case 'd': if (action & PWM_SHOW_CONFIG) usage(); action |= PWM_DUTY; - duty = strtol(optarg, &percent, 10); + duty = strtoul(optarg, &percent, 10); if (*percent == '%') { - if (duty < 0 || duty > 100) { - fprintf(stderr, + if (duty > 100) { + fprintf(stderr, "Invalid duty percentage\n"); usage(); } @@ -186,11 +186,11 @@ main(int argc, char *argv[]) state.period = period; if (action & PWM_DUTY) { if (*percent != '\0') - state.duty = state.period * duty / 100; + state.duty = (uint64_t)state.period * duty / 100; else state.duty = duty; } - + if (ioctl(fd, PWMSETSTATE, &state) == -1) { fprintf(stderr, "Cannot configure the pwm controller\n"); _______________________________________________ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"