mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 18:38:58 +00:00
config: use snprintf instead of sprintf
Due to the preconditions, there should never be an error, but it pays to be paranoid. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
This commit is contained in:
parent
956ad0ed6f
commit
0d280ea457
13
src/config.c
13
src/config.c
@ -648,7 +648,7 @@ static char *build_varname(const char *section, const char *name)
|
|||||||
static int parse_section_header_ext(const char *line, const char *base_name, char **section_name)
|
static int parse_section_header_ext(const char *line, const char *base_name, char **section_name)
|
||||||
{
|
{
|
||||||
int buf_len, total_len, pos, rpos;
|
int buf_len, total_len, pos, rpos;
|
||||||
int c;
|
int c, ret;
|
||||||
char *subsection, *first_quote, *last_quote;
|
char *subsection, *first_quote, *last_quote;
|
||||||
int error = GIT_SUCCESS;
|
int error = GIT_SUCCESS;
|
||||||
int quote_marks;
|
int quote_marks;
|
||||||
@ -713,7 +713,16 @@ static int parse_section_header_ext(const char *line, const char *base_name, cha
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(*section_name, "%s %s", base_name, subsection);
|
ret = snprintf(*section_name, total_len, "%s %s", base_name, subsection);
|
||||||
|
if (ret >= total_len) {
|
||||||
|
/* If this fails, we've checked the length wrong */
|
||||||
|
error = GIT_ERROR;
|
||||||
|
goto out;
|
||||||
|
} else if (ret < 0) {
|
||||||
|
error = GIT_EOSERR;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
git__strntolower(*section_name, strchr(*section_name, ' ') - *section_name);
|
git__strntolower(*section_name, strchr(*section_name, ' ') - *section_name);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
Loading…
Reference in New Issue
Block a user