Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shared: use proper data types in freadline_wrapped #81

Closed
wants to merge 1 commit into from

Conversation

stoeckmann
Copy link
Contributor

Do not use signed data types if unsigned arithmetic is expected, i.e. use size_t if processing sizes and unsigned int for line numbers due to given API of freadline_wrapped.

This fixes a possible signed integer overflow on 64 bit systems.

Proof of Concept:

  1. Create a file with a line longer than 2 GB
    dd if=/dev/zero bs=1024 count=2097153 | tr '\0' 'a' > /lib/modules/$(uname -r)/modules.weakdep

  2. Run lsmod compiled with -fsanitize=undefined
    lsmod

You will get an error like:
shared/util.c:330:10: runtime error: signed integer overflow: 1073741824 * 2 cannot be represented in type 'int'

Do not use signed data types if unsigned arithmetic is expected,
i.e. use size_t if processing sizes and unsigned int for line numbers
due to given API of freadline_wrapped.

This fixes a possible signed integer overflow on 64 bit systems.
Copy link
Collaborator

@evelikov evelikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks o/

lucasdemarchi pushed a commit that referenced this pull request Aug 22, 2024
Do not use signed data types if unsigned arithmetic is expected,
i.e. use size_t if processing sizes and unsigned int for line numbers
due to given API of freadline_wrapped.

This fixes a possible signed integer overflow on 64 bit systems.

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: #81
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
@lucasdemarchi
Copy link
Contributor

Applied, thanks.

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

Successfully merging this pull request may close these issues.

None yet

3 participants