Skip to content

[BUG] Integer range branch accepts trailing garbage (inconsistent strtol validation) #62

Description

@lucocozz

Summary

The range branch of parse_int_range() does not validate that the whole token is consumed, so trailing garbage is silently accepted — inconsistent with the single-value branch.

Location

source/callbacks/handlers/array_int_handler.cparse_int_range().

if (range_separator != NULL) {
    int start    = strtol(value, NULL, 10);
    int end      = strtol(range_separator + 1, NULL, 10);   // no endptr check
    range->start = MIN(start, end);
    range->end   = MAX(start, end);
    return 0;
}
// single-value branch DOES validate:
range->start = strtol(value, &endptr, 10);
if (*endptr != '\0')
    return -1;  // Invalid integer format

Mechanism

The single-value path rejects trailing junk via *endptr != '\0', but the range path passes NULL as endptr and never checks it. So --nums=1-5abc parses as the range 1..5 and silently ignores abc. Validation is inconsistent between the two paths.

Suggested fix

Use endptr on both strtol calls in the range branch and reject the token if either does not end at '\0' (allowing for the separator position on the first call).

Severity

Low — input-validation laxity, not a memory-safety issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions