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

setproctitle() unsafe use of vsprintf #5116

Open
MASHtm opened this issue Nov 5, 2024 · 3 comments
Open

setproctitle() unsafe use of vsprintf #5116

MASHtm opened this issue Nov 5, 2024 · 3 comments

Comments

@MASHtm
Copy link
Contributor

MASHtm commented Nov 5, 2024

I had some SIGABRTs recently and since the code in lib/setproctitle.c didn't change up to HEAD I wanted to ask your opinion on the use of vsprintf() in setproctitle() there. It uses a fixed sized destination and has to sprintf cmd.s. IMO (and the coredump suggests it as well) I had these SIGABRTs in vsprintf() because cmd.s was too large, because somebody tried some "HTTP fuzzing" on my imap and pop3 ports.

@elliefm
Copy link
Contributor

elliefm commented Nov 5, 2024

Yeah that does look unsafe. Something like this might sort it out:

diff --git a/lib/setproctitle.c b/lib/setproctitle.c
index d86c9283d..cd575b704 100644
--- a/lib/setproctitle.c
+++ b/lib/setproctitle.c
@@ -251,7 +251,7 @@ setproctitle(const char *fmt __attribute__((__unused__)), ...)
 
         /* print the argument string */
         VA_START(fmt);
-        (void) vsprintf(p, fmt, ap);
+        (void) vsnprintf(p, SPT_BUFSIZE, fmt, ap);
         VA_END;
 
         i = strlen(buf);

Not sure how to test this though. I can't remember how the setproctitle implementation hangs together... looks like there's a mess of things to define with -D in CFLAGS to enable and configure it, but it might also just use a libc one automatically if it's there (which wouldn't be affected by the bug in our implementation).

@MASHtm
Copy link
Contributor Author

MASHtm commented Nov 6, 2024

Yes, I added -DUSE_SETPROCTITLE to CFLAGS in my spec file. I think a "closing" null byte should also be forced.

@elliefm
Copy link
Contributor

elliefm commented Nov 7, 2024

That's not necessary, the snprintf and vsnprintf functions guarantee to always null-terminate the string. If the string and null byte won't both fit in the buffer together, the string is truncated until they do.

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

No branches or pull requests

2 participants