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

[PATCH 2/2] http-backend: Let gcc check the format of more printf-type functions.

From
TCTarmigan Casebolt <tarmigan+git@gmail.com>
Date
Nov 14, 2009, 21:10 UTC
Message-ID
<1258233058-2348-2-git-send-email-tarmigan+git@gmail.com>
In-Reply-To
<1258233058-2348-1-git-send-email-tarmigan+git@gmail.com>

We already have these checks in many printf-type functions that have prototypes which are in header files. Add these same checks to static functions in http-backend.c

Signed-off-by: Tarmigan Casebolt <tarmigan+git@gmail.com>
---

Shawn, please consider this patch in addition to the one that you posted that actually fixes the bug. With this patch, gcc will warn about that bug.

 http-backend.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/http-backend.c b/http-backend.c
index ab9433d..110b166 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -108,6 +108,7 @@ static const char *get_parameter(const char *name)
 	return i ? i->util : NULL;
 }
 
+__attribute__((format (printf, 2, 3)))
 static void format_write(int fd, const char *fmt, ...)
 {
 	static char buffer[1024];
@@ -165,6 +166,7 @@ static void end_headers(void)
 	safe_write(1, "\r\n", 2);
 }
 
+__attribute__((format (printf, 1, 2)))
 static NORETURN void not_found(const char *err, ...)
 {
 	va_list params;
@@ -180,6 +182,7 @@ static NORETURN void not_found(const char *err, ...)
 	exit(0);
 }
 
+__attribute__((format (printf, 1, 2)))
 static NORETURN void forbidden(const char *err, ...)
 {
 	va_list params;
-- 
1.6.5.51.g191f5
Previous: Tarmigan CaseboltNext: Shawn O. Pearce
Message 2 of 8 in “http-backend: Fix access beyond end of string.”
  1. 1/2 http-backend: Fix access beyond end of string.Tarmigan Casebolt, Nov 14, 2009
  2. 2/2 http-backend: Let gcc check the format of more printf-type functions.Tarmigan Casebolt, Nov 14, 2009
  3. Shawn O. PearceNov 16, 2009
  4. Shawn O. PearceNov 16, 2009
  5. Jeff KingNov 16, 2009
  6. Junio C HamanoNov 16, 2009
  7. TarmiganNov 17, 2009
  8. Brian GernhardtNov 23, 2009

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.