git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/7] imap-send: avoid buffer overflow

From
Jeff King <peff@peff.net>
Date
Dec 8, 2011, 08:23 UTC
Message-ID
<20111208082317.GA26409@sigill.intra.peff.net>
In-Reply-To
<20111208082118.GA1507@sigill.intra.peff.net>

We format the password prompt in an 80-character static buffer. It contains the remote host and username, so it's unlikely to overflow (or be exploitable by a remote attacker), but there's no reason not to be careful and use a strbuf.

Signed-off-by: Jeff King <peff@peff.net>
---
Just something I noticed while doing the cleanup in the next patch.
 imap-send.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index e1ad1a4..4c1e897 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1209,9 +1209,10 @@ static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const cha
 			goto bail;
 		}
 		if (!srvc->pass) {
-			char prompt[80];
-			sprintf(prompt, "Password (%s@%s): ", srvc->user, srvc->host);
-			arg = git_getpass(prompt);
+			struct strbuf prompt = STRBUF_INIT;
+			strbuf_addf(&prompt, "Password (%s@%s): ", srvc->user, srvc->host);
+			arg = git_getpass(prompt.buf);
+			strbuf_release(&prompt);
 			if (!arg) {
 				perror("getpass");
 				exit(1);
-- 
1.7.8.rc2.8.gf0f4f
Previous: Jeff KingNext: Jeff King
Message 2 of 11 in “[PATCHv2 0/7] getpass refactoring”
  1. Jeff KingDec 8, 2011
  2. 1/7 imap-send: avoid buffer overflowJeff King, Dec 8, 2011
  3. 2/7 imap-send: don't check return value of git_getpassJeff King, Dec 8, 2011
  4. 3/7 move git_getpass to its own source fileJeff King, Dec 8, 2011
  5. 4/7 refactor git_getpass into generic prompt functionJeff King, Dec 8, 2011
  6. Junio C HamanoDec 9, 2011
  7. 5/7 add generic terminal prompt functionJeff King, Dec 8, 2011
  8. Jakub NarebskiDec 8, 2011
  9. Jeff KingDec 8, 2011
  10. 6/7 prompt: use git_terminal_promptJeff King, Dec 8, 2011
  11. 7/7 credential: use git_prompt instead of git_getpassJeff King, Dec 8, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.