{"thread":{"id":"16253","subject":"[PATCH] Fixed non-literal format in printf-style calls","startedAt":"2008-11-10T19:15:17Z","lastAt":"2008-11-12T00:51:47Z","messageCount":4,"participants":["Daniel Lowe","Brandon Casey","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"95361","messageId":"1226344517-16120-1-git-send-email-dlowe@bitmuse.com","threadId":"16253","inReplyTo":null,"subject":"[PATCH] Fixed non-literal format in printf-style calls","fromName":"Daniel Lowe","fromEmail":"dlowe@bitmuse.com","sentAt":"2008-11-10T19:15:17Z","receivedAt":"2008-11-10T19:15:17Z","isPatch":true,"sender":{"key":"dlowe@bitmuse.com","avatar":null},"body":"These were found using gcc 4.3.2-1ubuntu11 with the warning:\n\nwarning: format not a string literal and no format arguments\n\n\n---\n builtin-check-attr.c |    2 +-\n builtin-remote.c     |    2 +-\n bundle.c             |    4 ++--\n environment.c        |    2 +-\n fsck.c               |    2 +-\n grep.c               |    6 +++---\n hash-object.c        |    2 +-\n path.c               |    4 ++--\n refs.c               |    2 +-\n unpack-trees.c       |    2 +-\n 10 files changed, 14 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin-check-attr.c b/builtin-check-attr.c\nindex 4921341..15a04b7 100644\n--- a/builtin-check-attr.c\n+++ b/builtin-check-attr.c\n@@ -97,7 +97,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)\n \telse if (stdin_paths && doubledash < argc)\n \t\terrstr = \"Can't specify files with --stdin\";\n \tif (errstr) {\n-\t\terror (errstr);\n+\t\terror(\"%s\", errstr);\n \t\tusage_with_options(check_attr_usage, check_attr_options);\n \t}\n\ndiff --git a/builtin-remote.c b/builtin-remote.c\nindex e396a3a..47deb0a 100644\n--- a/builtin-remote.c\n+++ b/builtin-remote.c\n@@ -320,7 +320,7 @@ static int add_branch_for_removal(const char *refname,\n\n \t/* make sure that symrefs are deleted */\n \tif (flags & REF_ISSYMREF)\n-\t\treturn unlink(git_path(refname));\n+\t\treturn unlink(git_path(\"%s\", refname));\n\n \titem = string_list_append(refname, branches->branches);\n \titem->util = xmalloc(20);\ndiff --git a/bundle.c b/bundle.c\nindex 7d17a1f..daecd8e 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -114,7 +114,7 @@ int verify_bundle(struct bundle_header *header, int verbose)\n \t\t\tcontinue;\n \t\t}\n \t\tif (++ret == 1)\n-\t\t\terror(message);\n+\t\t\terror(\"%s\", message);\n \t\terror(\"%s %s\", sha1_to_hex(e->sha1), e->name);\n \t}\n \tif (revs.pending.nr != p->nr)\n@@ -139,7 +139,7 @@ int verify_bundle(struct bundle_header *header, int verbose)\n \tfor (i = 0; i < req_nr; i++)\n \t\tif (!(refs.objects[i].item->flags & SHOWN)) {\n \t\t\tif (++ret == 1)\n-\t\t\t\terror(message);\n+\t\t\t\terror(\"%s\", message);\n \t\t\terror(\"%s %s\", sha1_to_hex(refs.objects[i].item->sha1),\n \t\t\t\trefs.objects[i].name);\n \t\t}\ndiff --git a/environment.c b/environment.c\nindex bf93a59..bb96ac0 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -118,7 +118,7 @@ const char *get_git_work_tree(void)\n \t\t\twork_tree = git_work_tree_cfg;\n \t\t\t/* make_absolute_path also normalizes the path */\n \t\t\tif (work_tree && !is_absolute_path(work_tree))\n-\t\t\t\twork_tree = xstrdup(make_absolute_path(git_path(work_tree)));\n+\t\t\t\twork_tree = xstrdup(make_absolute_path(git_path(\"%s\", work_tree)));\n \t\t} else if (work_tree)\n \t\t\twork_tree = xstrdup(make_absolute_path(work_tree));\n \t\tgit_work_tree_initialized = 1;\ndiff --git a/fsck.c b/fsck.c\nindex 0cf5f01..97f76c5 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -326,7 +326,7 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...)\n \t\t\tdie(\"this should not happen, your snprintf is broken\");\n \t}\n\n-\terror(sb.buf);\n+\terror(\"%s\", sb.buf);\n \tstrbuf_release(&sb);\n \treturn 1;\n }\ndiff --git a/grep.c b/grep.c\nindex e2c190a..1db60d9 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -514,7 +514,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,\n \t\t\t\tif (from <= last_shown)\n \t\t\t\t\tfrom = last_shown + 1;\n \t\t\t\tif (last_shown && from != last_shown + 1)\n-\t\t\t\t\tprintf(hunk_mark);\n+\t\t\t\t\tprintf(\"%s\", hunk_mark);\n \t\t\t\twhile (from < lno) {\n \t\t\t\t\tpcl = &prev[lno-from-1];\n \t\t\t\t\tshow_line(opt, pcl->bol, pcl->eol,\n@@ -524,7 +524,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,\n \t\t\t\tlast_shown = lno-1;\n \t\t\t}\n \t\t\tif (last_shown && lno != last_shown + 1)\n-\t\t\t\tprintf(hunk_mark);\n+\t\t\t\tprintf(\"%s\", hunk_mark);\n \t\t\tif (!opt->count)\n \t\t\t\tshow_line(opt, bol, eol, name, lno, ':');\n \t\t\tlast_shown = last_hit = lno;\n@@ -535,7 +535,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,\n \t\t\t * we need to show this line.\n \t\t\t */\n \t\t\tif (last_shown && lno != last_shown + 1)\n-\t\t\t\tprintf(hunk_mark);\n+\t\t\t\tprintf(\"%s\", hunk_mark);\n \t\t\tshow_line(opt, bol, eol, name, lno, '-');\n \t\t\tlast_shown = lno;\n \t\t}\ndiff --git a/hash-object.c b/hash-object.c\nindex 20937ff..846e91a 100644\n--- a/hash-object.c\n+++ b/hash-object.c\n@@ -110,7 +110,7 @@ int main(int argc, const char **argv)\n \t}\n\n \tif (errstr) {\n-\t\terror (errstr);\n+\t\terror(\"%s\", errstr);\n \t\tusage_with_options(hash_object_usage, hash_object_options);\n \t}\n\ndiff --git a/path.c b/path.c\nindex eb24017..ae2c724 100644\n--- a/path.c\n+++ b/path.c\n@@ -41,7 +41,7 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...)\n \tlen = vsnprintf(buf, n, fmt, args);\n \tva_end(args);\n \tif (len >= n) {\n-\t\tsnprintf(buf, n, bad_path);\n+\t\tsnprintf(buf, n, \"%s\", bad_path);\n \t\treturn buf;\n \t}\n \treturn cleanup_path(buf);\n@@ -63,7 +63,7 @@ static char *git_vsnpath(char *buf, size_t n, const char *fmt, va_list args)\n \t\tgoto bad;\n \treturn cleanup_path(buf);\n bad:\n-\tsnprintf(buf, n, bad_path);\n+\tsnprintf(buf, n, \"%s\", bad_path);\n \treturn buf;\n }\n\ndiff --git a/refs.c b/refs.c\nindex 42bde72..33ced65 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -940,7 +940,7 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)\n \t\t\tlock->lk->filename[i] = 0;\n \t\t\tpath = lock->lk->filename;\n \t\t} else {\n-\t\t\tpath = git_path(refname);\n+\t\t\tpath = git_path(\"%s\", refname);\n \t\t}\n \t\terr = unlink(path);\n \t\tif (err && errno != ENOENT) {\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex e5749ef..54f301d 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -352,7 +352,7 @@ static int unpack_failed(struct unpack_trees_options *o, const char *message)\n \tdiscard_index(&o->result);\n \tif (!o->gently) {\n \t\tif (message)\n-\t\t\treturn error(message);\n+\t\t\treturn error(\"%s\", message);\n \t\treturn -1;\n \t}\n \treturn -1;\n--\n1.6.0.4\n"},{"id":"95365","messageId":"3t9bmcAj9kThyafdZ9mPENosknipZInn9Qq9u9oVuN7X7qwiI4GqZg@cipher.nrlssc.navy.mil","threadId":"16253","inReplyTo":"1226344517-16120-1-git-send-email-dlowe@bitmuse.com","subject":"Re: [PATCH] Fixed non-literal format in printf-style calls","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-11-10T19:47:55Z","receivedAt":"2008-11-10T19:47:55Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Daniel Lowe wrote:\n\n<snip>\n\n>  }\n> diff --git a/grep.c b/grep.c\n> index e2c190a..1db60d9 100644\n> --- a/grep.c\n> +++ b/grep.c\n> @@ -514,7 +514,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,\n>  \t\t\t\tif (from <= last_shown)\n>  \t\t\t\t\tfrom = last_shown + 1;\n>  \t\t\t\tif (last_shown && from != last_shown + 1)\n> -\t\t\t\t\tprintf(hunk_mark);\n> +\t\t\t\t\tprintf(\"%s\", hunk_mark);\n\nPerhaps these should by changed to use fputs() instead.\n\n<snip>\n\n> diff --git a/path.c b/path.c\n> index eb24017..ae2c724 100644\n> --- a/path.c\n> +++ b/path.c\n> @@ -41,7 +41,7 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...)\n>  \tlen = vsnprintf(buf, n, fmt, args);\n>  \tva_end(args);\n>  \tif (len >= n) {\n> -\t\tsnprintf(buf, n, bad_path);\n> +\t\tsnprintf(buf, n, \"%s\", bad_path);\n\nand these should use strlcpy.\n\n-brandon\n"},{"id":"95388","messageId":"1226351272-22253-1-git-send-email-dlowe@bitmuse.com","threadId":"16253","inReplyTo":"3t9bmcAj9kThyafdZ9mPENosknipZInn9Qq9u9oVuN7X7qwiI4GqZg@cipher.nrlssc.navy.mil","subject":"[PATCH] Fixed non-literal format in printf-style calls","fromName":"Daniel Lowe","fromEmail":"dlowe@bitmuse.com","sentAt":"2008-11-10T21:07:52Z","receivedAt":"2008-11-10T21:07:52Z","isPatch":true,"sender":{"key":"dlowe@bitmuse.com","avatar":null},"body":"These were found using gcc 4.3.2-1ubuntu11 with the warning:\n\nwarning: format not a string literal and no format arguments\n\nIncorporated suggestions from Brandon Casey <casey@nrlssc.navy.mil>.\n\n---\n builtin-check-attr.c |    2 +-\n builtin-remote.c     |    2 +-\n bundle.c             |    4 ++--\n environment.c        |    2 +-\n fsck.c               |    2 +-\n grep.c               |    6 +++---\n hash-object.c        |    2 +-\n path.c               |    4 ++--\n refs.c               |    2 +-\n unpack-trees.c       |    2 +-\n 10 files changed, 14 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin-check-attr.c b/builtin-check-attr.c\nindex 4921341..15a04b7 100644\n--- a/builtin-check-attr.c\n+++ b/builtin-check-attr.c\n@@ -97,7 +97,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)\n \telse if (stdin_paths && doubledash < argc)\n \t\terrstr = \"Can't specify files with --stdin\";\n \tif (errstr) {\n-\t\terror (errstr);\n+\t\terror(\"%s\", errstr);\n \t\tusage_with_options(check_attr_usage, check_attr_options);\n \t}\n\ndiff --git a/builtin-remote.c b/builtin-remote.c\nindex e396a3a..47deb0a 100644\n--- a/builtin-remote.c\n+++ b/builtin-remote.c\n@@ -320,7 +320,7 @@ static int add_branch_for_removal(const char *refname,\n\n \t/* make sure that symrefs are deleted */\n \tif (flags & REF_ISSYMREF)\n-\t\treturn unlink(git_path(refname));\n+\t\treturn unlink(git_path(\"%s\", refname));\n\n \titem = string_list_append(refname, branches->branches);\n \titem->util = xmalloc(20);\ndiff --git a/bundle.c b/bundle.c\nindex 7d17a1f..daecd8e 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -114,7 +114,7 @@ int verify_bundle(struct bundle_header *header, int verbose)\n \t\t\tcontinue;\n \t\t}\n \t\tif (++ret == 1)\n-\t\t\terror(message);\n+\t\t\terror(\"%s\", message);\n \t\terror(\"%s %s\", sha1_to_hex(e->sha1), e->name);\n \t}\n \tif (revs.pending.nr != p->nr)\n@@ -139,7 +139,7 @@ int verify_bundle(struct bundle_header *header, int verbose)\n \tfor (i = 0; i < req_nr; i++)\n \t\tif (!(refs.objects[i].item->flags & SHOWN)) {\n \t\t\tif (++ret == 1)\n-\t\t\t\terror(message);\n+\t\t\t\terror(\"%s\", message);\n \t\t\terror(\"%s %s\", sha1_to_hex(refs.objects[i].item->sha1),\n \t\t\t\trefs.objects[i].name);\n \t\t}\ndiff --git a/environment.c b/environment.c\nindex bf93a59..bb96ac0 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -118,7 +118,7 @@ const char *get_git_work_tree(void)\n \t\t\twork_tree = git_work_tree_cfg;\n \t\t\t/* make_absolute_path also normalizes the path */\n \t\t\tif (work_tree && !is_absolute_path(work_tree))\n-\t\t\t\twork_tree = xstrdup(make_absolute_path(git_path(work_tree)));\n+\t\t\t\twork_tree = xstrdup(make_absolute_path(git_path(\"%s\", work_tree)));\n \t\t} else if (work_tree)\n \t\t\twork_tree = xstrdup(make_absolute_path(work_tree));\n \t\tgit_work_tree_initialized = 1;\ndiff --git a/fsck.c b/fsck.c\nindex 0cf5f01..97f76c5 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -326,7 +326,7 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...)\n \t\t\tdie(\"this should not happen, your snprintf is broken\");\n \t}\n\n-\terror(sb.buf);\n+\terror(\"%s\", sb.buf);\n \tstrbuf_release(&sb);\n \treturn 1;\n }\ndiff --git a/grep.c b/grep.c\nindex e2c190a..600f69f 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -514,7 +514,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,\n \t\t\t\tif (from <= last_shown)\n \t\t\t\t\tfrom = last_shown + 1;\n \t\t\t\tif (last_shown && from != last_shown + 1)\n-\t\t\t\t\tprintf(hunk_mark);\n+\t\t\t\t\tfputs(hunk_mark, stdout);\n \t\t\t\twhile (from < lno) {\n \t\t\t\t\tpcl = &prev[lno-from-1];\n \t\t\t\t\tshow_line(opt, pcl->bol, pcl->eol,\n@@ -524,7 +524,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,\n \t\t\t\tlast_shown = lno-1;\n \t\t\t}\n \t\t\tif (last_shown && lno != last_shown + 1)\n-\t\t\t\tprintf(hunk_mark);\n+\t\t\t\tfputs(hunk_mark, stdout);\n \t\t\tif (!opt->count)\n \t\t\t\tshow_line(opt, bol, eol, name, lno, ':');\n \t\t\tlast_shown = last_hit = lno;\n@@ -535,7 +535,7 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name,\n \t\t\t * we need to show this line.\n \t\t\t */\n \t\t\tif (last_shown && lno != last_shown + 1)\n-\t\t\t\tprintf(hunk_mark);\n+\t\t\t\tfputs(hunk_mark, stdout);\n \t\t\tshow_line(opt, bol, eol, name, lno, '-');\n \t\t\tlast_shown = lno;\n \t\t}\ndiff --git a/hash-object.c b/hash-object.c\nindex 20937ff..846e91a 100644\n--- a/hash-object.c\n+++ b/hash-object.c\n@@ -110,7 +110,7 @@ int main(int argc, const char **argv)\n \t}\n\n \tif (errstr) {\n-\t\terror (errstr);\n+\t\terror(\"%s\", errstr);\n \t\tusage_with_options(hash_object_usage, hash_object_options);\n \t}\n\ndiff --git a/path.c b/path.c\nindex eb24017..a074aea 100644\n--- a/path.c\n+++ b/path.c\n@@ -41,7 +41,7 @@ char *mksnpath(char *buf, size_t n, const char *fmt, ...)\n \tlen = vsnprintf(buf, n, fmt, args);\n \tva_end(args);\n \tif (len >= n) {\n-\t\tsnprintf(buf, n, bad_path);\n+\t\tstrlcpy(buf, bad_path, n);\n \t\treturn buf;\n \t}\n \treturn cleanup_path(buf);\n@@ -63,7 +63,7 @@ static char *git_vsnpath(char *buf, size_t n, const char *fmt, va_list args)\n \t\tgoto bad;\n \treturn cleanup_path(buf);\n bad:\n-\tsnprintf(buf, n, bad_path);\n+\tstrlcpy(buf, bad_path, n);\n \treturn buf;\n }\n\ndiff --git a/refs.c b/refs.c\nindex 42bde72..33ced65 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -940,7 +940,7 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)\n \t\t\tlock->lk->filename[i] = 0;\n \t\t\tpath = lock->lk->filename;\n \t\t} else {\n-\t\t\tpath = git_path(refname);\n+\t\t\tpath = git_path(\"%s\", refname);\n \t\t}\n \t\terr = unlink(path);\n \t\tif (err && errno != ENOENT) {\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex e5749ef..54f301d 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -352,7 +352,7 @@ static int unpack_failed(struct unpack_trees_options *o, const char *message)\n \tdiscard_index(&o->result);\n \tif (!o->gently) {\n \t\tif (message)\n-\t\t\treturn error(message);\n+\t\t\treturn error(\"%s\", message);\n \t\treturn -1;\n \t}\n \treturn -1;\n--\n1.6.0.4\n"},{"id":"95519","messageId":"7viqqtu5p8.fsf@gitster.siamese.dyndns.org","threadId":"16253","inReplyTo":"1226351272-22253-1-git-send-email-dlowe@bitmuse.com","subject":"Re: [PATCH] Fix non-literal format in printf-style calls","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-11-12T00:51:47Z","receivedAt":"2008-11-12T00:51:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, will apply to 'maint' and 'master' after splitting.\n"}]}