-
Notifications
You must be signed in to change notification settings - Fork 138
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
Address CodeQL gripe about uncontrolled format string in handling of GEARMAND_PORT #411
Address CodeQL gripe about uncontrolled format string in handling of GEARMAND_PORT #411
Conversation
Hi Ed. Thanks for taking this on. I don't love the approach of silently dropping non-numeric chars. The real problem is the way we're constructing the buffer for gearmand_gai_error. I'd much rather see that changed to be an argument with a %s as the format string. |
@SpamapS wrote:
I suspect that
It doesn't work that way. Or the gearmand_log_* functions are too labyrinthine for me to discern a way of doing that. That said, I think changing the gearmand/libgearman-server/gearmand.cc Line 616 in 728f3a5
Or we could get rid of lines 614 to 620 entirely and change line 626 from gearmand/libgearman-server/gearmand.cc Line 626 in 728f3a5
to simply gearmand/libgearman-server/gearmand.cc Line 642 in 728f3a5
|
Actually no, I forgot, ports can be non-numeric! /etc/services defines names for some ports. So we can't just ditch the non-numerics. Honestly, the way the code uses message/format interchangeably is a bit disturbing. format should always be protected and ideally is only programmer-input never user-input. I don't know how far down the rabbit hole you're up for going, but if we could make a gearmand_gai_error alternative that takes both a format and a message, and use that instead of building the buffer, that would be the ideal IMO. Otherwise, yeah, maybe just drop the detail in the error message. |
It's not |
a5ed043
to
28b449a
Compare
@SpamapS : Updated. Please review the latest revision. |
…f the GEARMAND_PORT environment variable by changing how gearmand_log_gai_error() calls gearmand_log_perror().
28b449a
to
3f9a48f
Compare
ARGH! I hate GitHub Actions so much! All CI workflows are failing. It all worked a month ago! |
This merge request addresses CodeQL's gripe about an "uncontrolled format string" alert around line 626 of
libgearman-server/gearmand.cc
. The alert suggests that, if a user sets theGEARMAND_PORT
environment variable to a string with percent characters in it, for example, it could result in a buffer overflow and/or crash the program. (Refer to meta-issue #406.)This merge request addresses that by limiting the string to at most 5 characters (since 65535 is the maximum port number) and then truncating the string at the first non-digit character.I believe this PR also addresses issue #320 with Kubernetes settingGEARMAND_PORT
to unexpected values by default.