imap-send: avoid buffer overflow

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Dec 10, 2011 at 05:40 UTC 50d0158fbba5c4cd04184bb757bf43a84c290405
1 file changed +4 -3
imap-send.c
+4 -3
@@ -1209,9 +1209,10 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
1209 goto bail;
1210 }
1211 if (!srvc->pass) {
1212 - char prompt[80];
1213 - sprintf(prompt, "Password (%s@%s): ", srvc->user, srvc->host);
1214 - arg = git_getpass(prompt);
1212 + struct strbuf prompt = STRBUF_INIT;
1213 + strbuf_addf(&prompt, "Password (%s@%s): ", srvc->user, srvc->host);
1214 + arg = git_getpass(prompt.buf);
1215 + strbuf_release(&prompt);
1216 if (!arg) {
1217 perror("getpass");
1218 exit(1);