Skip to content

Incorrect handling of the BACKSPACE key in getln() function. #439

@kemonats

Description

@kemonats

Existing code:

sudo/src/tgetpass.c

Lines 413 to 419 in 627ae4b

} else if (c == sudo_term_erase) {
if (cp > buf) {
ignore_result(write(fd, "\b \b", 3));
cp--;
left++;
}
continue;

If the first key pressed is BACKSPACE, the left variable is decreased by 1, the
pointer cp == buf and the reading of the next key is performed.
I think in this case, the left variable should be incremented by 1,
While if there are inserted values in the buf variable, the left variable should be
incremented by 2.
That is, the BACKSPACE handling should look like this:

} else if (c == sudo_term_erase) {
    if (cp > buf) {
        ignore_result(write(fd, "\b \b", 3));
        cp--;
        left++;
    }
    left++;
    continue;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions