Merge pull request #4834 from pks-t/pks/v0.27.5 · RetVal/libgit2@8e0b172 · GitHub
Skip to content

Commit 8e0b172

Browse files
authored
Merge pull request libgit2#4834 from pks-t/pks/v0.27.5
Security release v0.27.5
2 parents 8b89f36 + c590b41 commit 8e0b172

12 files changed

Lines changed: 740 additions & 206 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 47 additions & 0 deletions

‎include/git2/version.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#ifndef INCLUDE_git_version_h__
88
#define INCLUDE_git_version_h__
99

10-
#define LIBGIT2_VERSION "0.27.4"
10+
#define LIBGIT2_VERSION "0.27.5"
1111
#define LIBGIT2_VER_MAJOR 0
1212
#define LIBGIT2_VER_MINOR 27
13-
#define LIBGIT2_VER_REVISION 4
13+
#define LIBGIT2_VER_REVISION 5
1414
#define LIBGIT2_VER_PATCH 0
1515

1616
#define LIBGIT2_SOVERSION 27

‎src/config_file.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,9 @@ static int parse_include(git_config_parser *reader,
928928
char *dir;
929929
int result;
930930

931+
if (!file)
932+
return 0;
933+
931934
if ((result = git_path_dirname_r(&path, reader->file->path)) < 0)
932935
return result;
933936

@@ -1029,7 +1032,7 @@ static int parse_conditional_include(git_config_parser *reader,
10291032
size_t i;
10301033
int error = 0, matches;
10311034

1032-
if (!parse_data->repo)
1035+
if (!parse_data->repo || !file)
10331036
return 0;
10341037

10351038
condition = git__substrdup(section + strlen("includeIf."),

‎src/config_parse.c‎

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -315,49 +315,51 @@ static int unescape_line(
315315

316316
static int parse_multiline_variable(git_config_parser *reader, git_buf *value, int in_quotes)
317317
{
318-
char *line = NULL, *proc_line = NULL;
319318
int quote_count;
320-
bool multiline;
319+
bool multiline = true;
321320

322-
/* Check that the next line exists */
323-
git_parse_advance_line(&reader->ctx);
324-
line = git__strndup(reader->ctx.line, reader->ctx.line_len);
325-
if (line == NULL)
326-
return -1;
321+
while (multiline) {
322+
char *line = NULL, *proc_line = NULL;
323+
int error;
327324

328-
/* We've reached the end of the file, there is no continuation.
329-
* (this is not an error).
330-
*/
331-
if (line[0] == '\0') {
332-
git__free(line);
333-
return 0;
334-
}
325+
/* Check that the next line exists */
326+
git_parse_advance_line(&reader->ctx);
327+
line = git__strndup(reader->ctx.line, reader->ctx.line_len);
328+
GITERR_CHECK_ALLOC(line);
329+
330+
/*
331+
* We've reached the end of the file, there is no continuation.
332+
* (this is not an error).
333+
*/
334+
if (line[0] == '\0') {
335+
error = 0;
336+
goto out;
337+
}
335338

336-
quote_count = strip_comments(line, !!in_quotes);
339+
/* If it was just a comment, pretend it didn't exist */
340+
quote_count = strip_comments(line, !!in_quotes);
341+
if (line[0] == '\0')
342+
goto next;
337343

338-
/* If it was just a comment, pretend it didn't exist */
339-
if (line[0] == '\0') {
344+
if ((error = unescape_line(&proc_line, &multiline,
345+
line, in_quotes)) < 0)
346+
goto out;
347+
348+
/* Add this line to the multiline var */
349+
if ((error = git_buf_puts(value, proc_line)) < 0)
350+
goto out;
351+
352+
next:
340353
git__free(line);
341-
return parse_multiline_variable(reader, value, quote_count);
342-
/* TODO: unbounded recursion. This **could** be exploitable */
343-
}
354+
git__free(proc_line);
355+
in_quotes = quote_count;
356+
continue;
344357

345-
if (unescape_line(&proc_line, &multiline, line, in_quotes) < 0) {
358+
out:
346359
git__free(line);
347-
return -1;
360+
git__free(proc_line);
361+
return error;
348362
}
349-
/* add this line to the multiline var */
350-
351-
git_buf_puts(value, proc_line);
352-
git__free(line);
353-
git__free(proc_line);
354-
355-
/*
356-
* If we need to continue reading the next line, let's just
357-
* keep putting stuff in the buffer
358-
*/
359-
if (multiline)
360-
return parse_multiline_variable(reader, value, quote_count);
361363

362364
return 0;
363365
}

‎src/odb_pack.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static int packfile_load__cb(void *data, git_buf *path)
210210
for (i = 0; i < backend->packs.length; ++i) {
211211
struct git_pack_file *p = git_vector_get(&backend->packs, i);
212212

213-
if (memcmp(p->pack_name, path_str, cmp_len) == 0)
213+
if (strncmp(p->pack_name, path_str, cmp_len) == 0)
214214
return 0;
215215
}
216216

‎src/submodule.c‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,14 @@ static int get_value(const char **out, git_config *cfg, git_buf *buf, const char
18131813
return error;
18141814
}
18151815

1816+
static bool looks_like_command_line_option(const char *s)
1817+
{
1818+
if (s && s[0] == '-')
1819+
return true;
1820+
1821+
return false;
1822+
}
1823+
18161824
static int submodule_read_config(git_submodule *sm, git_config *cfg)
18171825
{
18181826
git_buf key = GIT_BUF_INIT;
@@ -1826,24 +1834,31 @@ static int submodule_read_config(git_submodule *sm, git_config *cfg)
18261834

18271835
if ((error = get_value(&value, cfg, &key, sm->name, "path")) == 0) {
18281836
in_config = 1;
1837+
/* We would warn here if we had that API */
1838+
if (!looks_like_command_line_option(value)) {
18291839
/*
18301840
* TODO: if case insensitive filesystem, then the following strcmp
18311841
* should be strcasecmp
18321842
*/
1833-
if (strcmp(sm->name, value) != 0) {
1834-
if (sm->path != sm->name)
1835-
git__free(sm->path);
1836-
sm->path = git__strdup(value);
1837-
GITERR_CHECK_ALLOC(sm->path);
1843+
if (strcmp(sm->name, value) != 0) {
1844+
if (sm->path != sm->name)
1845+
git__free(sm->path);
1846+
sm->path = git__strdup(value);
1847+
GITERR_CHECK_ALLOC(sm->path);
1848+
}
1849+
18381850
}
18391851
} else if (error != GIT_ENOTFOUND) {
18401852
goto cleanup;
18411853
}
18421854

18431855
if ((error = get_value(&value, cfg, &key, sm->name, "url")) == 0) {
1844-
in_config = 1;
1845-
sm->url = git__strdup(value);
1846-
GITERR_CHECK_ALLOC(sm->url);
1856+
/* We would warn here if we had that API */
1857+
if (!looks_like_command_line_option(value)) {
1858+
in_config = 1;
1859+
sm->url = git__strdup(value);
1860+
GITERR_CHECK_ALLOC(sm->url);
1861+
}
18471862
} else if (error != GIT_ENOTFOUND) {
18481863
goto cleanup;
18491864
}

‎src/transports/smart.h‎

Lines changed: 16 additions & 16 deletions

0 commit comments

Comments
 (0)