Skip to content

Commit ce4d4e7

Browse files
committed
Merge branch 'maint-2.5' into maint-2.6
* maint-2.5: Git 2.5.5 Git 2.4.11 list-objects: pass full pathname to callbacks list-objects: drop name_path entirely list-objects: convert name_path to a strbuf show_object_with_name: simplify by using path_name() http-push: stop using name_path tree-diff: catch integer overflow in combine_diff_path allocation add helpers for detecting size_t overflow
2 parents 833e482 + e568e56 commit ce4d4e7

16 files changed

+110
-148
lines changed

Documentation/RelNotes/2.4.11.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Git v2.4.11 Release Notes
2+
=========================
3+
4+
Fixes since v2.4.10
5+
-------------------
6+
7+
* Bugfix patches were backported from the 'master' front to plug heap
8+
corruption holes, to catch integer overflow in the computation of
9+
pathname lengths, and to get rid of the name_path API. Both of
10+
these would have resulted in writing over an under-allocated buffer
11+
when formulating pathnames while tree traversal.

Documentation/RelNotes/2.5.5.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Git v2.5.5 Release Notes
2+
========================
3+
4+
Fixes since v2.5.4
5+
------------------
6+
7+
* Bugfix patches were backported from the 'master' front to plug heap
8+
corruption holes, to catch integer overflow in the computation of
9+
pathname lengths, and to get rid of the name_path API. Both of
10+
these would have resulted in writing over an under-allocated buffer
11+
when formulating pathnames while tree traversal.

Documentation/git.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,20 @@ Documentation for older releases are available here:
5353
link:RelNotes/2.6.1.txt[2.6.1],
5454
link:RelNotes/2.6.0.txt[2.6].
5555

56-
* link:v2.5.4/git.html[documentation for release 2.5.4]
56+
* link:v2.5.5/git.html[documentation for release 2.5.5]
5757

5858
* release notes for
59+
link:RelNotes/2.5.5.txt[2.5.5],
5960
link:RelNotes/2.5.4.txt[2.5.4],
6061
link:RelNotes/2.5.3.txt[2.5.3],
6162
link:RelNotes/2.5.2.txt[2.5.2],
6263
link:RelNotes/2.5.1.txt[2.5.1],
6364
link:RelNotes/2.5.0.txt[2.5].
6465

65-
* link:v2.4.10/git.html[documentation for release 2.4.10]
66+
* link:v2.4.11/git.html[documentation for release 2.4.11]
6667

6768
* release notes for
69+
link:RelNotes/2.4.11.txt[2.4.11],
6870
link:RelNotes/2.4.10.txt[2.4.10],
6971
link:RelNotes/2.4.9.txt[2.4.9],
7072
link:RelNotes/2.4.8.txt[2.4.8],

builtin/pack-objects.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,21 +2284,11 @@ static void show_commit(struct commit *commit, void *data)
22842284
index_commit_for_bitmap(commit);
22852285
}
22862286

2287-
static void show_object(struct object *obj,
2288-
const struct name_path *path, const char *last,
2289-
void *data)
2287+
static void show_object(struct object *obj, const char *name, void *data)
22902288
{
2291-
char *name = path_name(path, last);
2292-
22932289
add_preferred_base_object(name);
22942290
add_object_entry(obj->sha1, obj->type, name, 0);
22952291
obj->flags |= OBJECT_ADDED;
2296-
2297-
/*
2298-
* We will have generated the hash from the name,
2299-
* but not saved a pointer to it - we can free it
2300-
*/
2301-
free((char *)name);
23022292
}
23032293

23042294
static void show_edge(struct commit *commit)
@@ -2480,8 +2470,7 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
24802470
}
24812471

24822472
static void record_recent_object(struct object *obj,
2483-
const struct name_path *path,
2484-
const char *last,
2473+
const char *name,
24852474
void *data)
24862475
{
24872476
sha1_array_append(&recent_objects, obj->sha1);

builtin/rev-list.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ static void finish_commit(struct commit *commit, void *data)
177177
free_commit_buffer(commit);
178178
}
179179

180-
static void finish_object(struct object *obj,
181-
const struct name_path *path, const char *name,
182-
void *cb_data)
180+
static void finish_object(struct object *obj, const char *name, void *cb_data)
183181
{
184182
struct rev_list_info *info = cb_data;
185183
if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1))
@@ -188,15 +186,13 @@ static void finish_object(struct object *obj,
188186
parse_object(obj->sha1);
189187
}
190188

191-
static void show_object(struct object *obj,
192-
const struct name_path *path, const char *component,
193-
void *cb_data)
189+
static void show_object(struct object *obj, const char *name, void *cb_data)
194190
{
195191
struct rev_list_info *info = cb_data;
196-
finish_object(obj, path, component, cb_data);
192+
finish_object(obj, name, cb_data);
197193
if (info->flags & REV_LIST_QUIET)
198194
return;
199-
show_object_with_name(stdout, obj, path, component);
195+
show_object_with_name(stdout, obj, name);
200196
}
201197

202198
static void show_edge(struct commit *commit)

diff.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ struct combine_diff_path {
222222
} parent[FLEX_ARRAY];
223223
};
224224
#define combine_diff_path_size(n, l) \
225-
(sizeof(struct combine_diff_path) + \
226-
sizeof(struct combine_diff_parent) * (n) + (l) + 1)
225+
st_add4(sizeof(struct combine_diff_path), (l), 1, \
226+
st_mult(sizeof(struct combine_diff_parent), (n)))
227227

228228
extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
229229
int dense, struct rev_info *);

git-compat-util.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@
9696
#define unsigned_add_overflows(a, b) \
9797
((b) > maximum_unsigned_value_of_type(a) - (a))
9898

99+
/*
100+
* Returns true if the multiplication of "a" and "b" will
101+
* overflow. The types of "a" and "b" must match and must be unsigned.
102+
* Note that this macro evaluates "a" twice!
103+
*/
104+
#define unsigned_mult_overflows(a, b) \
105+
((a) && (b) > maximum_unsigned_value_of_type(a) / (a))
106+
99107
#ifdef __GNUC__
100108
#define TYPEOF(x) (__typeof__(x))
101109
#else
@@ -703,6 +711,32 @@ extern void release_pack_memory(size_t);
703711
typedef void (*try_to_free_t)(size_t);
704712
extern try_to_free_t set_try_to_free_routine(try_to_free_t);
705713

714+
static inline size_t st_add(size_t a, size_t b)
715+
{
716+
if (unsigned_add_overflows(a, b))
717+
die("size_t overflow: %"PRIuMAX" + %"PRIuMAX,
718+
(uintmax_t)a, (uintmax_t)b);
719+
return a + b;
720+
}
721+
#define st_add3(a,b,c) st_add((a),st_add((b),(c)))
722+
#define st_add4(a,b,c,d) st_add((a),st_add3((b),(c),(d)))
723+
724+
static inline size_t st_mult(size_t a, size_t b)
725+
{
726+
if (unsigned_mult_overflows(a, b))
727+
die("size_t overflow: %"PRIuMAX" * %"PRIuMAX,
728+
(uintmax_t)a, (uintmax_t)b);
729+
return a * b;
730+
}
731+
732+
static inline size_t st_sub(size_t a, size_t b)
733+
{
734+
if (a < b)
735+
die("size_t underflow: %"PRIuMAX" - %"PRIuMAX,
736+
(uintmax_t)a, (uintmax_t)b);
737+
return a - b;
738+
}
739+
706740
#ifdef HAVE_ALLOCA_H
707741
# include <alloca.h>
708742
# define xalloca(size) (alloca(size))

http-push.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,9 +1276,7 @@ static struct object_list **add_one_object(struct object *obj, struct object_lis
12761276
}
12771277

12781278
static struct object_list **process_blob(struct blob *blob,
1279-
struct object_list **p,
1280-
struct name_path *path,
1281-
const char *name)
1279+
struct object_list **p)
12821280
{
12831281
struct object *obj = &blob->object;
12841282

@@ -1292,14 +1290,11 @@ static struct object_list **process_blob(struct blob *blob,
12921290
}
12931291

12941292
static struct object_list **process_tree(struct tree *tree,
1295-
struct object_list **p,
1296-
struct name_path *path,
1297-
const char *name)
1293+
struct object_list **p)
12981294
{
12991295
struct object *obj = &tree->object;
13001296
struct tree_desc desc;
13011297
struct name_entry entry;
1302-
struct name_path me;
13031298

13041299
obj->flags |= LOCAL;
13051300

@@ -1309,21 +1304,17 @@ static struct object_list **process_tree(struct tree *tree,
13091304
die("bad tree object %s", sha1_to_hex(obj->sha1));
13101305

13111306
obj->flags |= SEEN;
1312-
name = xstrdup(name);
13131307
p = add_one_object(obj, p);
1314-
me.up = path;
1315-
me.elem = name;
1316-
me.elem_len = strlen(name);
13171308

13181309
init_tree_desc(&desc, tree->buffer, tree->size);
13191310

13201311
while (tree_entry(&desc, &entry))
13211312
switch (object_type(entry.mode)) {
13221313
case OBJ_TREE:
1323-
p = process_tree(lookup_tree(entry.sha1), p, &me, name);
1314+
p = process_tree(lookup_tree(entry.sha1), p);
13241315
break;
13251316
case OBJ_BLOB:
1326-
p = process_blob(lookup_blob(entry.sha1), p, &me, name);
1317+
p = process_blob(lookup_blob(entry.sha1), p);
13271318
break;
13281319
default:
13291320
/* Subproject commit - not in this repository */
@@ -1342,7 +1333,7 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
13421333
int count = 0;
13431334

13441335
while ((commit = get_revision(revs)) != NULL) {
1345-
p = process_tree(commit->tree, p, NULL, "");
1336+
p = process_tree(commit->tree, p);
13461337
commit->object.flags |= LOCAL;
13471338
if (!(commit->object.flags & UNINTERESTING))
13481339
count += add_send_request(&commit->object, lock);
@@ -1361,11 +1352,11 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
13611352
continue;
13621353
}
13631354
if (obj->type == OBJ_TREE) {
1364-
p = process_tree((struct tree *)obj, p, NULL, name);
1355+
p = process_tree((struct tree *)obj, p);
13651356
continue;
13661357
}
13671358
if (obj->type == OBJ_BLOB) {
1368-
p = process_blob((struct blob *)obj, p, NULL, name);
1359+
p = process_blob((struct blob *)obj, p);
13691360
continue;
13701361
}
13711362
die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name);

list-objects.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
static void process_blob(struct rev_info *revs,
1212
struct blob *blob,
1313
show_object_fn show,
14-
struct name_path *path,
14+
struct strbuf *path,
1515
const char *name,
1616
void *cb_data)
1717
{
1818
struct object *obj = &blob->object;
19+
size_t pathlen;
1920

2021
if (!revs->blob_objects)
2122
return;
@@ -24,7 +25,11 @@ static void process_blob(struct rev_info *revs,
2425
if (obj->flags & (UNINTERESTING | SEEN))
2526
return;
2627
obj->flags |= SEEN;
27-
show(obj, path, name, cb_data);
28+
29+
pathlen = path->len;
30+
strbuf_addstr(path, name);
31+
show(obj, path->buf, cb_data);
32+
strbuf_setlen(path, pathlen);
2833
}
2934

3035
/*
@@ -52,7 +57,7 @@ static void process_blob(struct rev_info *revs,
5257
static void process_gitlink(struct rev_info *revs,
5358
const unsigned char *sha1,
5459
show_object_fn show,
55-
struct name_path *path,
60+
struct strbuf *path,
5661
const char *name,
5762
void *cb_data)
5863
{
@@ -62,15 +67,13 @@ static void process_gitlink(struct rev_info *revs,
6267
static void process_tree(struct rev_info *revs,
6368
struct tree *tree,
6469
show_object_fn show,
65-
struct name_path *path,
6670
struct strbuf *base,
6771
const char *name,
6872
void *cb_data)
6973
{
7074
struct object *obj = &tree->object;
7175
struct tree_desc desc;
7276
struct name_entry entry;
73-
struct name_path me;
7477
enum interesting match = revs->diffopt.pathspec.nr == 0 ?
7578
all_entries_interesting: entry_not_interesting;
7679
int baselen = base->len;
@@ -86,17 +89,12 @@ static void process_tree(struct rev_info *revs,
8689
return;
8790
die("bad tree object %s", sha1_to_hex(obj->sha1));
8891
}
92+
8993
obj->flags |= SEEN;
90-
show(obj, path, name, cb_data);
91-
me.up = path;
92-
me.elem = name;
93-
me.elem_len = strlen(name);
94-
95-
if (!match) {
96-
strbuf_addstr(base, name);
97-
if (base->len)
98-
strbuf_addch(base, '/');
99-
}
94+
strbuf_addstr(base, name);
95+
show(obj, base->buf, cb_data);
96+
if (base->len)
97+
strbuf_addch(base, '/');
10098

10199
init_tree_desc(&desc, tree->buffer, tree->size);
102100

@@ -113,16 +111,16 @@ static void process_tree(struct rev_info *revs,
113111
if (S_ISDIR(entry.mode))
114112
process_tree(revs,
115113
lookup_tree(entry.sha1),
116-
show, &me, base, entry.path,
114+
show, base, entry.path,
117115
cb_data);
118116
else if (S_ISGITLINK(entry.mode))
119117
process_gitlink(revs, entry.sha1,
120-
show, &me, entry.path,
118+
show, base, entry.path,
121119
cb_data);
122120
else
123121
process_blob(revs,
124122
lookup_blob(entry.sha1),
125-
show, &me, entry.path,
123+
show, base, entry.path,
126124
cb_data);
127125
}
128126
strbuf_setlen(base, baselen);
@@ -213,19 +211,19 @@ void traverse_commit_list(struct rev_info *revs,
213211
continue;
214212
if (obj->type == OBJ_TAG) {
215213
obj->flags |= SEEN;
216-
show_object(obj, NULL, name, data);
214+
show_object(obj, name, data);
217215
continue;
218216
}
219217
if (!path)
220218
path = "";
221219
if (obj->type == OBJ_TREE) {
222220
process_tree(revs, (struct tree *)obj, show_object,
223-
NULL, &base, path, data);
221+
&base, path, data);
224222
continue;
225223
}
226224
if (obj->type == OBJ_BLOB) {
227225
process_blob(revs, (struct blob *)obj, show_object,
228-
NULL, path, data);
226+
&base, path, data);
229227
continue;
230228
}
231229
die("unknown pending object %s (%s)",

list-objects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define LIST_OBJECTS_H
33

44
typedef void (*show_commit_fn)(struct commit *, void *);
5-
typedef void (*show_object_fn)(struct object *, const struct name_path *, const char *, void *);
5+
typedef void (*show_object_fn)(struct object *, const char *, void *);
66
void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *);
77

88
typedef void (*show_edge_fn)(struct commit *);

pack-bitmap-write.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ static uint32_t find_object_pos(const unsigned char *sha1)
148148
return entry->in_pack_pos;
149149
}
150150

151-
static void show_object(struct object *object, const struct name_path *path,
152-
const char *last, void *data)
151+
static void show_object(struct object *object, const char *name, void *data)
153152
{
154153
struct bitmap *base = data;
155154
bitmap_set(base, find_object_pos(object->sha1));

0 commit comments

Comments
 (0)