Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 211e117

Browse files
committed
Merge pull request libgit2#3739 from ethomson/0.24.1
Backport bug fixes to 0.24
2 parents 785d8c4 + 8edadbf commit 211e117

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+689
-282
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ IF (MSVC)
412412
# /MTd - Statically link the multithreaded debug version of the CRT
413413
# /MDd - Dynamically link the multithreaded debug version of the CRT
414414
# /RTC1 - Run time checks
415-
SET(CMAKE_C_FLAGS_DEBUG "/Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}")
415+
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}")
416416

417417
# /DNDEBUG - Disables asserts
418418
# /MT - Statically link the multithreaded release version of the CRT
@@ -464,7 +464,7 @@ ELSE ()
464464
ENDIF()
465465

466466
IF (WIN32 AND NOT CYGWIN)
467-
SET(CMAKE_C_FLAGS_DEBUG "-D_DEBUG")
467+
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
468468
ENDIF ()
469469

470470
IF (MINGW) # MinGW always does PIC and complains if we tell it to
@@ -608,6 +608,8 @@ IF (SONAME)
608608
IF (LIBGIT2_FILENAME)
609609
ADD_DEFINITIONS(-DLIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
610610
SET_TARGET_PROPERTIES(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
611+
ELSEIF (DEFINED LIBGIT2_PREFIX)
612+
SET_TARGET_PROPERTIES(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}")
611613
ENDIF()
612614
ENDIF()
613615
STRING(REPLACE ";" " " LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS}")

deps/http-parser/http_parser.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ do { \
9999
FOR##_mark = NULL; \
100100
} \
101101
} while (0)
102-
102+
103103
/* Run the data callback FOR and consume the current byte */
104104
#define CALLBACK_DATA(FOR) \
105105
CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1)
@@ -444,14 +444,17 @@ parse_url_char(enum state s, const char ch)
444444
return s_req_path;
445445
}
446446

447+
/* The schema must start with an alpha character. After that, it may
448+
* consist of digits, '+', '-' or '.', followed by a ':'.
449+
*/
447450
if (IS_ALPHA(ch)) {
448451
return s_req_schema;
449452
}
450453

451454
break;
452455

453456
case s_req_schema:
454-
if (IS_ALPHA(ch)) {
457+
if (IS_ALPHANUM(ch) || ch == '+' || ch == '-' || ch == '.') {
455458
return s;
456459
}
457460

include/git2/common.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@
2424
GIT_BEGIN_DECL
2525
# include "inttypes.h"
2626
GIT_END_DECL
27-
#else
27+
/** This check is needed for importing this file in an iOS/OS X framework throws an error in Xcode otherwise.*/
28+
#elif !defined(__CLANG_INTTYPES_H)
2829
# include <inttypes.h>
2930
#endif
3031

32+
#ifdef DOCURIUM
33+
/*
34+
* This is so clang's doc parser acknowledges comments on functions
35+
* with size_t parameters.
36+
*/
37+
typedef size_t size_t;
38+
#endif
39+
3140
/** Declare a public function exported for application use. */
3241
#if __GNUC__ >= 4
3342
# define GIT_EXTERN(type) extern \
@@ -148,6 +157,7 @@ typedef enum {
148157
GIT_OPT_SET_SSL_CERT_LOCATIONS,
149158
GIT_OPT_SET_USER_AGENT,
150159
GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
160+
GIT_OPT_SET_SSL_CIPHERS,
151161
} git_libgit2_opt_t;
152162

153163
/**
@@ -259,6 +269,11 @@ typedef enum {
259269
* > example, when this is enabled, the parent(s) and tree inputs
260270
* > will be validated when creating a new commit. This defaults
261271
* > to disabled.
272+
* * opts(GIT_OPT_SET_SSL_CIPHERS, const char *ciphers)
273+
*
274+
* > Set the SSL ciphers use for HTTPS connections.
275+
* >
276+
* > - `ciphers` is the list of ciphers that are eanbled.
262277
*
263278
* @param option Option key
264279
* @param ... value to set the option

script/coverity.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,24 @@ COVERITY_UNSUPPORTED=1 \
4949
# Upload results
5050
tar czf libgit2.tgz cov-int
5151
SHA=$(git rev-parse --short HEAD)
52-
curl \
52+
53+
HTML="$(curl \
54+
--silent \
55+
--write-out "\n%{http_code}" \
5356
--form token="$COVERITY_TOKEN" \
5457
5558
5659
--form version="$SHA" \
5760
--form description="Travis build" \
58-
https://scan.coverity.com/builds?project=libgit2
61+
https://scan.coverity.com/builds?project=libgit2)"
62+
# Body is everything up to the last line
63+
BODY="$(echo "$HTML" | head -n-1)"
64+
# Status code is the last line
65+
STATUS_CODE="$(echo "$HTML" | tail -n1)"
66+
67+
echo "${BODY}"
68+
69+
if [ "${STATUS_CODE}" != "201" ]; then
70+
echo "Received error code ${STATUS_CODE} from Coverity"
71+
exit 1
72+
fi

src/array.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,44 @@ GIT_INLINE(void *) git_array_grow(void *_a, size_t item_size)
8282

8383
#define git_array_valid_index(a, i) ((i) < (a).size)
8484

85+
#define git_array_foreach(a, i, element) \
86+
for ((i) = 0; (i) < (a).size && ((element) = &(a).ptr[(i)]); (i)++)
87+
88+
89+
GIT_INLINE(int) git_array__search(
90+
size_t *out,
91+
void *array_ptr,
92+
size_t item_size,
93+
size_t array_len,
94+
int (*compare)(const void *, const void *),
95+
const void *key)
96+
{
97+
size_t lim;
98+
unsigned char *part, *array = array_ptr, *base = array_ptr;
99+
int cmp;
100+
101+
for (lim = array_len; lim != 0; lim >>= 1) {
102+
part = base + (lim >> 1) * item_size;
103+
cmp = (*compare)(key, part);
104+
105+
if (cmp == 0) {
106+
base = part;
107+
break;
108+
}
109+
if (cmp > 0) { /* key > p; take right partition */
110+
base = part + 1 * item_size;
111+
lim--;
112+
} /* else take left partition */
113+
}
114+
115+
if (out)
116+
*out = (base - array) / item_size;
117+
118+
return (cmp == 0) ? 0 : GIT_ENOTFOUND;
119+
}
120+
121+
#define git_array_search(out, a, cmp, key) \
122+
git_array__search(out, (a).ptr, sizeof(*(a).ptr), (a).size, \
123+
(cmp), (key))
124+
85125
#endif

src/blame.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const git_blame_hunk *git_blame_get_hunk_byline(git_blame *blame, size_t lineno)
178178
return NULL;
179179
}
180180

181-
static void normalize_options(
181+
static int normalize_options(
182182
git_blame_options *out,
183183
const git_blame_options *in,
184184
git_repository *repo)
@@ -190,7 +190,9 @@ static void normalize_options(
190190

191191
/* No newest_commit => HEAD */
192192
if (git_oid_iszero(&out->newest_commit)) {
193-
git_reference_name_to_id(&out->newest_commit, repo, "HEAD");
193+
if (git_reference_name_to_id(&out->newest_commit, repo, "HEAD") < 0) {
194+
return -1;
195+
}
194196
}
195197

196198
/* min_line 0 really means 1 */
@@ -204,6 +206,8 @@ static void normalize_options(
204206
out->flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES;
205207
if (out->flags & GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES)
206208
out->flags |= GIT_BLAME_TRACK_COPIES_SAME_FILE;
209+
210+
return 0;
207211
}
208212

209213
static git_blame_hunk *split_hunk_in_vector(
@@ -362,7 +366,8 @@ int git_blame_file(
362366
git_blame *blame = NULL;
363367

364368
assert(out && repo && path);
365-
normalize_options(&normOptions, options, repo);
369+
if ((error = normalize_options(&normOptions, options, repo)) < 0)
370+
goto on_error;
366371

367372
blame = git_blame__alloc(repo, normOptions, path);
368373
GITERR_CHECK_ALLOC(blame);

src/blame_git.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
525525
if (sg_origin[i])
526526
continue;
527527

528-
git_commit_parent(&p, origin->commit, i);
528+
if ((error = git_commit_parent(&p, origin->commit, i)) < 0)
529+
goto finish;
529530
porigin = find_origin(blame, p, origin);
530531

531532
if (!porigin)

src/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ int git_commit_extract_signature(git_buf *signature, git_buf *signed_data, git_r
676676

677677
buf = git_odb_object_data(obj);
678678

679-
while ((h = strchr(buf, '\n')) && h[1] != '\0' && h[1] != '\n') {
679+
while ((h = strchr(buf, '\n')) && h[1] != '\0') {
680680
h++;
681681
if (git__prefixcmp(buf, field)) {
682682
if (git_buf_put(signed_data, buf, h - buf) < 0)

src/config_cache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ int git_config__cvar(int *out, git_config *config, git_cvar_cached cvar)
8686
struct map_data *data = &_cvar_maps[(int)cvar];
8787
git_config_entry *entry;
8888

89-
git_config__lookup_entry(&entry, config, data->cvar_name, false);
89+
if ((error = git_config__lookup_entry(&entry, config, data->cvar_name, false)) < 0)
90+
return error;
9091

9192
if (!entry)
9293
*out = data->default_value;

src/config_file.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -553,30 +553,15 @@ static int config_set_multivar(
553553
git_config_backend *cfg, const char *name, const char *regexp, const char *value)
554554
{
555555
diskfile_backend *b = (diskfile_backend *)cfg;
556-
refcounted_strmap *map;
557-
git_strmap *values;
558556
char *key;
559557
regex_t preg;
560558
int result;
561-
khiter_t pos;
562559

563560
assert(regexp);
564561

565562
if ((result = git_config__normalize_name(name, &key)) < 0)
566563
return result;
567564

568-
map = refcounted_strmap_take(&b->header);
569-
values = b->header.values->values;
570-
571-
pos = git_strmap_lookup_index(values, key);
572-
if (!git_strmap_valid_index(values, pos)) {
573-
/* If we don't have it, behave like a normal set */
574-
result = config_set(cfg, name, value);
575-
refcounted_strmap_free(map);
576-
git__free(key);
577-
return result;
578-
}
579-
580565
result = regcomp(&preg, regexp, REG_EXTENDED);
581566
if (result != 0) {
582567
giterr_set_regex(&preg, result);
@@ -591,7 +576,6 @@ static int config_set_multivar(
591576
result = config_refresh(cfg);
592577

593578
out:
594-
refcounted_strmap_free(map);
595579
git__free(key);
596580
regfree(&preg);
597581

@@ -1032,6 +1016,11 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
10321016
*/
10331017

10341018
first_quote = strchr(line, '"');
1019+
if (first_quote == NULL) {
1020+
set_parse_error(reader, 0, "Missing quotation marks in section header");
1021+
return -1;
1022+
}
1023+
10351024
last_quote = strrchr(line, '"');
10361025
quoted_len = last_quote - first_quote;
10371026

@@ -1483,7 +1472,7 @@ static int config_parse(
14831472
int (*on_section)(struct reader **reader, const char *current_section, const char *line, size_t line_len, void *data),
14841473
int (*on_variable)(struct reader **reader, const char *current_section, char *var_name, char *var_value, const char *line, size_t line_len, void *data),
14851474
int (*on_comment)(struct reader **reader, const char *line, size_t line_len, void *data),
1486-
int (*on_eof)(struct reader **reader, void *data),
1475+
int (*on_eof)(struct reader **reader, const char *current_section, void *data),
14871476
void *data)
14881477
{
14891478
char *current_section = NULL, *var_name, *var_value, *line_start;
@@ -1534,7 +1523,7 @@ static int config_parse(
15341523
}
15351524

15361525
if (on_eof)
1537-
result = on_eof(&reader, data);
1526+
result = on_eof(&reader, current_section, data);
15381527

15391528
git__free(current_section);
15401529
return result;
@@ -1850,7 +1839,8 @@ static int write_on_comment(struct reader **reader, const char *line, size_t lin
18501839
return write_line_to(&write_data->buffered_comment, line, line_len);
18511840
}
18521841

1853-
static int write_on_eof(struct reader **reader, void *data)
1842+
static int write_on_eof(
1843+
struct reader **reader, const char *current_section, void *data)
18541844
{
18551845
struct write_data *write_data = (struct write_data *)data;
18561846
int result = 0;
@@ -1869,7 +1859,11 @@ static int write_on_eof(struct reader **reader, void *data)
18691859
* value.
18701860
*/
18711861
if ((!write_data->preg || !write_data->preg_replaced) && write_data->value) {
1872-
if ((result = write_section(write_data->buf, write_data->section)) == 0)
1862+
/* write the section header unless we're already in it */
1863+
if (!current_section || strcmp(current_section, write_data->section))
1864+
result = write_section(write_data->buf, write_data->section);
1865+
1866+
if (!result)
18731867
result = write_value(write_data);
18741868
}
18751869

0 commit comments

Comments
 (0)