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

Avoid UB when packing a domain name #1613

Closed
wants to merge 4 commits into from

Conversation

jtstrs
Copy link
Contributor

@jtstrs jtstrs commented Dec 5, 2023

rfc1035NamePack() called rfc1035LabelPack() with a nil label buffer.
Feeding memcpy() a nil buffer is undefined behavior, even if size is 0.

@squid-prbot
Copy link
Collaborator

Can one of the admins verify this patch?

@jtstrs
Copy link
Contributor Author

jtstrs commented Dec 5, 2023

Using memcpy is undefined behiour according to
https://en.cppreference.com/w/cpp/string/byte/memcpy

If either dest or src is an [invalid or null pointer],
the behavior is undefined, even if count is zero.

Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

Thank you for working on fixing this bug!

src/dns/rfc1035.cc Outdated Show resolved Hide resolved
@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Dec 12, 2023
jtstrs and others added 2 commits December 13, 2023 11:55
When I suggested the new comment text,
I did not know that RFC 1034 had the following text: 

    the null (i.e., zero length) label used for the root.
@rousskov rousskov changed the title Avoid UB when packing name Avoid UB when packing a domain name Dec 13, 2023
Copy link
Contributor

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

Thank you for addressing my primary concern. I am approving this PR after polishing its code and PR metadata a little. @jtstrs, please double check my changes.

src/dns/rfc1035.cc Show resolved Hide resolved
Copy link
Contributor

@yadij yadij left a comment

Choose a reason for hiding this comment

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

We still have the UB implied by potential memcpy() mistakes. But replacing the one in label packing with memove() can be done when the other ones are updated.

src/dns/rfc1035.cc Show resolved Hide resolved
@yadij yadij added M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels S-could-use-an-approval An approval may speed this PR merger (but is not required) and removed S-waiting-for-author author action is expected (and usually required) labels Dec 17, 2023
@rousskov rousskov removed the S-could-use-an-approval An approval may speed this PR merger (but is not required) label Dec 18, 2023
@rousskov
Copy link
Contributor

OK to test

@squid-anubis squid-anubis added the M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels label Dec 22, 2023
squid-anubis pushed a commit that referenced this pull request Dec 22, 2023
rfc1035NamePack() called rfc1035LabelPack() with a nil label buffer.
Feeding memcpy() a nil buffer is undefined behavior, even if size is 0.
@squid-anubis squid-anubis added M-failed-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-failed-staging-other https://github.com/measurement-factory/anubis#pull-request-labels and removed M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels labels Dec 22, 2023
@kinkie
Copy link
Contributor

kinkie commented Dec 22, 2023

OK to test

@kinkie kinkie removed M-failed-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-failed-staging-other https://github.com/measurement-factory/anubis#pull-request-labels labels Dec 24, 2023
squid-anubis pushed a commit that referenced this pull request Dec 24, 2023
rfc1035NamePack() called rfc1035LabelPack() with a nil label buffer.
Feeding memcpy() a nil buffer is undefined behavior, even if size is 0.
@squid-anubis squid-anubis added the M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels label Dec 24, 2023
@squid-anubis squid-anubis removed the M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels label Dec 25, 2023
@squid-anubis squid-anubis added M-merged https://github.com/measurement-factory/anubis#pull-request-labels and removed M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels labels Dec 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-merged https://github.com/measurement-factory/anubis#pull-request-labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants