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

CA-220442: Check length of socket name before copying #202

Closed
wants to merge 1 commit into from

Conversation

kostaslambda
Copy link
Contributor

'struct sockaddr_un' member 'sun_path' is a fixed size, 108 byte array.
Check that 'name' is at maximum 107 characters long before copying.

Signed-off-by: Kostas Ladopoulos konstantinos.ladopoulos@citrix.com

@@ -187,6 +187,13 @@ tap_ctl_connect(const char *name, int *sfd)

memset(&saddr, 0, sizeof(saddr));
saddr.sun_family = AF_UNIX;

if (unlikely(strlen(name) > sizeof(saddr.sun_path) - 1)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This line should be more readable by adding parenthesis around sizeof and -1 instead of relying on operator precedence.

I do see your point in raising an error instead of truncating and keep going

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree changing 'sizeof(saddr.sun_path) - 1" to '(sizeof(saddr.sun_path) - 1)' would make it a bit more readable

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a random line taken from the linux kernel

if (unlikely(!bvl && (gfp_mask & __GFP_DIRECT_RECLAIM)))

I think whoever wrote the block layer knows C enough, nevertheless they felt the need to
make it readable.

There is a difference between readable and understanble

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even pull the maximum allowed size out as a constant and use that, no parens required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

apples and oranges...

@germanop
Copy link
Contributor

germanop commented Sep 6, 2016

Don't quite understand the apple and oranges comment.
That said, there was no need to mention the 108 chars in the commit message, given we are
using sizeof.

I am getting the commit as is, I think we spent far too much time on this one.

'struct sockaddr_un' member 'sun_path' is a fixed size, 108 byte array.
Check that 'name' is at maximum 107 characters long before copying.

Signed-off-by: Kostas Ladopoulos <konstantinos.ladopoulos@citrix.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants