Skip to content

lib/uklibparam: Minimum value of a signed parameter is rejected as out of range #1932

Open

Description

@RaphaelFakhri

Describe the bug

uklibparam rejects the minimum value of every signed parameter type. For example, passing -128 to an __s8 parameter fails:

libuklibparam.test_s8=-128 --
ERR:  [libuklibparam] <parser.c @  479> Parameter libuklibparam.test_s8 (s8): Given number is out of range

The same happens for -32768 (__s16), -2147483648 (__s32), and -9223372036854775808 (__s64). Values one above the minimum are accepted.

Cause

do_check_num() in lib/uklibparam/parser.c compares the parsed magnitude with the type maximum before it applies the sign:

if (num > (unsigned long long) max)
	goto outofrange;

The magnitude of the minimum of a signed type is max + 1, so this check fails before the negative range check runs.

Steps to reproduce

  1. Register a parameter with UK_LIBPARAM_PARAM(x, __s8, "...").
  2. Boot with <prefix>.x=-128 --.
  3. The parser prints "Given number is out of range" and x keeps its default value.

Expected behavior

x is set to -128.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions