-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
FIX(overlay): Add strlen check of XDG_RUNTIME_DIR before strcpy #6990
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
base: master
Are you sure you want to change the base?
FIX(overlay): Add strlen check of XDG_RUNTIME_DIR before strcpy #6990
Conversation
WalkthroughA length validation check is introduced to the XDG_RUNTIME_DIR path handling in overlay.c. The modification ensures that before using the environment variable to construct a Unix socket path, both the pointer is non-NULL and the string length does not exceed the buffer size of ctx->saName.sun_path. This prevents potential buffer overflow during path concatenation. The control flow remains unchanged: if the validation passes, the code sets PF_UNIX and constructs the path as before; otherwise, it falls back to using the user's home directory path. Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
overlay_gl/overlay.c (1)
162-166: Missing buffer overflow protection for home directory path.The fallback path using the home directory has no length validation before
strcpyandstrcat. If the home directory path is long, this will overflowctx->saName.sun_path.Apply this diff to add bounds checking:
} else if (home) { - ctx->saName.sun_family = PF_UNIX; - strcpy(ctx->saName.sun_path, home); - strcat(ctx->saName.sun_path, "/.MumbleOverlayPipe"); + if (strlen(home) + 19 < sizeof(ctx->saName.sun_path)) { + ctx->saName.sun_family = PF_UNIX; + strcpy(ctx->saName.sun_path, home); + strcat(ctx->saName.sun_path, "/.MumbleOverlayPipe"); + } }Or use
snprintffor both paths:} else if (home) { ctx->saName.sun_family = PF_UNIX; - strcpy(ctx->saName.sun_path, home); - strcat(ctx->saName.sun_path, "/.MumbleOverlayPipe"); + int ret = snprintf(ctx->saName.sun_path, sizeof(ctx->saName.sun_path), "%s/.MumbleOverlayPipe", home); + if (ret < 0 || (size_t)ret >= sizeof(ctx->saName.sun_path)) { + ctx->saName.sun_family = 0; + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
overlay_gl/overlay.c(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: PR (Windows_x64)
- GitHub Check: PR (Linux)
- GitHub Check: PR (Translations)
- GitHub Check: PR (macOS)
- GitHub Check: PR (Docs)
- GitHub Check: freebsd
overlay_gl/overlay.c
Outdated
| char *xdgRuntimeDir = getenv("XDG_RUNTIME_DIR"); | ||
|
|
||
| if (xdgRuntimeDir != NULL) { | ||
| if (xdgRuntimeDir != NULL && strlen(xdgRuntimeDir) + 18 < sizeof(ctx->saName.sun_path)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the + 18 for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the length of the string "/MumbleOverlayPipe". This also needs to fit into the ctx->saName.sun_path buffer.
The + 19 is the same just for the string "/.MumbleOverlayPipe"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I guess it would be better to use strlen on the corresponding string constant instead of using a "magic number".
And if no such constant exists yet, we should create one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I understand. I thought about using strlen but then the strings /MumbleOverlayPipe and /.MumbleOverlayPipe would have to be written twice. Neither option is pretty I guess.
I can move both string into their own char * variables, and use that variable in strlen and strcat if that sounds reasonable to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's hat I had in mind 👍
|
Why did the builds fail? |
|
Could you please rebase your branch against the current master branch and squash your commits into one? |
e10ec08 to
3b4fd86
Compare
|
Note, you need to first fetch from our repo (upstream) to make sure you got the latest changes from our master branch. Then rebase against that branch instead of your local version of I.e. do from your repo while having your branch checked out |
dea4f68 to
eb9f1d8
Compare
|
Okey, thanks. I think this should work now? Sorry for the extra steps here |
|
@Krzmbrzl Is this good to go? |
eb9f1d8 to
7757a91
Compare
Add length checks for XDG_RUNTIME_DIR and HOME environment variables before using strcpy() to build the overlay pipe path.
7757a91 to
866a9cf
Compare
Add a length check of the XDG_RUNTIME_DIR environment variable before using strcpy, to ensure it fits inside the ctx->saName.sun_path buffer. Before this commit, if the value from the XDG_RUNTIME_DIR was above the size of the ctx->saName.sun_path buffer, it would overflow the buffer.