Bug 253736 - backlight(8) arg parsing can be tricked in a small way
Summary: backlight(8) arg parsing can be tricked in a small way
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-21 07:35 UTC by corvid
Modified: 2022-05-25 14:23 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description corvid 2021-02-21 07:35:09 UTC
Incrementing or decrementing by 0 changes brightness by 10 instead.
Comment 1 David Schlachter 2021-02-27 01:34:01 UTC
Appears to be by design, see line 199 of usr.bin/backlight/backlight.c:

    percent = percent == 0 ? 10 : percent;

If this behavior isn't changed to do nothing instead, it should maybe be documented on the man page. I imagine the idea is to incr/decr by 10 only if no percentage is provided, rather than to do this specifically given a percentage of zero.
Comment 2 David Schlachter 2021-02-27 19:02:16 UTC
Simple fix:

diff --git a/usr.bin/backlight/backlight.c b/usr.bin/backlight/backlight.c
index 1dae0cfe5c6..180b9114876 100644
--- a/usr.bin/backlight/backlight.c
+++ b/usr.bin/backlight/backlight.c
@@ -98,7 +98,7 @@ main(int argc, char *argv[])
                BACKLIGHTGETSTATUS,
                BACKLIGHTUPDATESTATUS,
                BACKLIGHTGETINFO};
-       long percent = 0;
+       long percent = -1;
        const char *percent_error;
        uint32_t i;
        bool setname;
@@ -196,7 +196,7 @@ main(int argc, char *argv[])
        case BACKLIGHT_DECR:
                if (ioctl(fd, BACKLIGHTGETSTATUS, &props) == -1)
                        errx(1, "Cannot query the backlight device");
-               percent = percent == 0 ? 10 : percent;
+               percent = percent == -1 ? 10 : percent;
                percent = action == BACKLIGHT_INCR ? percent : -percent;
                props.brightness += percent;
                if ((int)props.brightness < 0)
Comment 3 commit-hook freebsd_committer freebsd_triage 2021-03-03 08:03:11 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3b005d51bd0fe4d8d19fb2df4d470b6e8baebf16

commit 3b005d51bd0fe4d8d19fb2df4d470b6e8baebf16
Author:     David Schlachter <fbsd-bugzilla@schlachter.ca>
AuthorDate: 2021-03-03 07:57:35 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2021-03-03 07:57:35 +0000

    backlight: Fix incr/decr with percent value of 0

    This now does nothing instead of incr/decr by 10%

    MFC After:    3 days
    PR:           253736

 usr.bin/backlight/backlight.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2021-03-10 10:54:31 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=9ba393f2ca0fd561c1fbf96f38eb014d7f883381

commit 9ba393f2ca0fd561c1fbf96f38eb014d7f883381
Author:     David Schlachter <fbsd-bugzilla@schlachter.ca>
AuthorDate: 2021-03-03 07:57:35 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2021-03-10 10:49:25 +0000

    backlight: Fix incr/decr with percent value of 0

    This now does nothing instead of incr/decr by 10%

    MFC After:    3 days
    PR:           253736

    (cherry picked from commit 3b005d51bd0fe4d8d19fb2df4d470b6e8baebf16)

 usr.bin/backlight/backlight.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2021-03-11 08:50:34 UTC
A commit in branch releng/13.0 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=cb603e3ea2d4f2fee8fa4e59bda7e27704b6899c

commit cb603e3ea2d4f2fee8fa4e59bda7e27704b6899c
Author:     David Schlachter <fbsd-bugzilla@schlachter.ca>
AuthorDate: 2021-03-03 07:57:35 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2021-03-11 08:49:03 +0000

    backlight: Fix incr/decr with percent value of 0

    This now does nothing instead of incr/decr by 10%

    MFC After:    3 days
    PR:           253736
    Approved by:  re (gjb)

    (cherry picked from commit 3b005d51bd0fe4d8d19fb2df4d470b6e8baebf16)
    (cherry picked from commit 9ba393f2ca0fd561c1fbf96f38eb014d7f883381)

 usr.bin/backlight/backlight.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)