Skip to content

Commit

Permalink
Merge pull request #1136 from krobelus/empty-format-nil-deref
Browse files Browse the repository at this point in the history
Fix null dereferences on unset format strings
  • Loading branch information
jonas authored Sep 25, 2021
2 parents 7771deb + a0506d9 commit b396a5d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/argv.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ format_append_argv(struct format_context *format, const char ***dst_argv, const
int argc;

if (!src_argv)
return true;
return argv_append(dst_argv, "");

for (argc = 0; src_argv[argc]; argc++)
if (!format_append_arg(format, dst_argv, src_argv[argc]))
return false;

return src_argv[argc] == NULL;
return true;
}

static bool
Expand Down
43 changes: 43 additions & 0 deletions test/regressions/github-1136-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

. libtest.sh
. libgit.sh

LINES=10

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"

# This runs an empty command, hence the empty pager.
test_case bang-cmdlineargs-doesnt-crash \
--args='status' \
--script='
:!%(cmdlineargs)
' <<EOF
[pager] 0%
EOF

test_case echo-cmdlineargs-doesnt-crash \
--args='status' \
--script='
:echo %(cmdlineargs)
' <<EOF
On branch master
Changes to be committed:
(no files)
Changes not staged for commit:
(no files)
Untracked files:
(no files)
[status] Nothing to update 100%
EOF

run_test_cases

0 comments on commit b396a5d

Please sign in to comment.