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

Chapter 4.3. - Calling strlen on NULL #46

Open
pixelshot91 opened this issue Feb 21, 2024 · 1 comment · May be fixed by #47
Open

Chapter 4.3. - Calling strlen on NULL #46

pixelshot91 opened this issue Feb 21, 2024 · 1 comment · May be fixed by #47

Comments

@pixelshot91
Copy link

In the C code here https://highassurance.rs/chp4/attack_1.html#breaking-temporal-memory-safety-value-validity,

    char* greeting = get_greeting();
    size_t greeting_len = strlen(greeting); // Excludes null byte  <-- Calling `strlen` before checking that greeting is non null
    if (greeting != NULL) {

We call strlen before checking that greeting is non-null, resulting in Undefined Behavior

@tnballo
Copy link
Owner

tnballo commented Feb 21, 2024

Ah, awesome catch! Would you like to PR a fix (probably move the strlen call into the if body)?

We could also add a sentence or two to the text noting that the strlen call must happen after the NULL check to avoid UB. Feels worth calling out in retrospect!

@pixelshot91 pixelshot91 linked a pull request Feb 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants