Skip to content

Commit c3a700f

Browse files
peffgitster
authored andcommitted
reflog_expire_cfg: NUL-terminate pattern field
You can tweak the reflog expiration for a particular subset of refs by configuring gc.foo.reflogexpire. We keep a linked list of reflog_expire_cfg structs, each of which holds the pattern and a "len" field for the length of the pattern. The pattern itself is _not_ NUL-terminated. However, we feed the pattern directly to wildmatch(), which expects a NUL-terminated string, meaning it may keep reading random junk after our struct. We can fix this by allocating an extra byte for the NUL (which is already zero because we use xcalloc). Let's also drop the misleading "len" field, which is no longer necessary. The existing use of "len" can be converted to use strncmp(). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a08595f commit c3a700f

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

builtin/reflog.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ static struct reflog_expire_cfg {
396396
struct reflog_expire_cfg *next;
397397
unsigned long expire_total;
398398
unsigned long expire_unreachable;
399-
size_t len;
400399
char pattern[FLEX_ARRAY];
401400
} *reflog_expire_cfg, **reflog_expire_cfg_tail;
402401

@@ -408,13 +407,12 @@ static struct reflog_expire_cfg *find_cfg_ent(const char *pattern, size_t len)
408407
reflog_expire_cfg_tail = &reflog_expire_cfg;
409408

410409
for (ent = reflog_expire_cfg; ent; ent = ent->next)
411-
if (ent->len == len &&
412-
!memcmp(ent->pattern, pattern, len))
410+
if (!strncmp(ent->pattern, pattern, len) &&
411+
ent->pattern[len] == '\0')
413412
return ent;
414413

415-
ent = xcalloc(1, (sizeof(*ent) + len));
414+
ent = xcalloc(1, sizeof(*ent) + len + 1);
416415
memcpy(ent->pattern, pattern, len);
417-
ent->len = len;
418416
*reflog_expire_cfg_tail = ent;
419417
reflog_expire_cfg_tail = &(ent->next);
420418
return ent;

0 commit comments

Comments
 (0)