Date: Mon, 12 Oct 2020 11:04:53 +0000 (UTC) From: Andriy Gapon <avg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r366643 - stable/12/usr.sbin/pwm Message-ID: <202010121104.09CB4rIc084865@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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");
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202010121104.09CB4rIc084865>