Skip to content

integer wrapping for last -N #38

@vinc17fr

Description

@vinc17fr

In src/wtmpdb.c for last -N:

          maxentries = maxentries * 10 + c - '0';

can yield an integer wrapping (maxentries is an unsigned integer, so not really an integer overflow, but unexpected wrapping).

For instance, last -18446744073709551617 outputs only 1 entry.

A fix could probably be something like that:

          if (maxentries > (ULONG_MAX - (c - '0')) / 10)
            maxentries = ULONG_MAX;
          else
            maxentries = maxentries * 10 + c - '0';

There is no such issue with -n because strtoul is used in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions