Skip to content

Commit

Permalink
config_set_multivar(): disallow newlines in keys
Browse files Browse the repository at this point in the history
This will no longer work:

$ git repo-config 'key.with
newline' some-value

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Jan 20, 2007
1 parent d23842f commit 6f71686
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,11 @@ int git_config_set_multivar(const char* key, const char* value,
goto out_free;
}
c = tolower(c);
} else if (c == '\n') {
fprintf(stderr, "invalid key (newline): %s\n", key);
free(store.key);
ret = 1;
goto out_free;
}
store.key[i] = c;
}
Expand Down
6 changes: 6 additions & 0 deletions t/t1300-repo-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,11 @@ EOF

test_expect_success 'quoting' 'cmp .git/config expect'

test_expect_failure 'key with newline' 'git repo-config key.with\\\
newline 123'

test_expect_success 'value with newline' 'git repo-config key.sub value.with\\\
newline'

test_done

0 comments on commit 6f71686

Please sign in to comment.