Skip to content

Commit a60a66e

Browse files
pks-tgitster
authored andcommitted
attr: harden allocation against integer overflows
When parsing an attributes line, we need to allocate an array that holds all attributes specified for the given file pattern. The calculation to determine the number of bytes that need to be allocated was prone to an overflow though when there was an unreasonable amount of attributes. Harden the allocation by instead using the `st_` helper functions that cause us to die when we hit an integer overflow. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e1e12e9 commit a60a66e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

attr.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,9 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
380380
goto fail_return;
381381
}
382382

383-
res = xcalloc(1,
384-
sizeof(*res) +
385-
sizeof(struct attr_state) * num_attr +
386-
(is_macro ? 0 : namelen + 1));
383+
res = xcalloc(1, st_add3(sizeof(*res),
384+
st_mult(sizeof(struct attr_state), num_attr),
385+
is_macro ? 0 : namelen + 1));
387386
if (is_macro) {
388387
res->u.attr = git_attr_internal(name, namelen);
389388
} else {

0 commit comments

Comments
 (0)