Commit 38ae878
read_gitfile_gently: fix use-after-free
The "dir" variable is a pointer into the "buf" array. When
we hit the cleanup_return path, the first thing we do is
free(buf); but one of the error messages prints "dir", which
will access the memory after the free.
We can fix this by reorganizing the error path a little. We
act on the fatal, error-printing conditions first, as they
want to access memory and do not care about freeing. Then we
free any memory, and finally return.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>1 parent 0179ca7 commit 38ae878
1 file changed
Lines changed: 5 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | | - | |
483 | | - | |
484 | 482 | | |
485 | 483 | | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
| 484 | + | |
491 | 485 | | |
492 | 486 | | |
493 | 487 | | |
494 | | - | |
| 488 | + | |
| 489 | + | |
495 | 490 | | |
496 | 491 | | |
497 | 492 | | |
| |||
509 | 504 | | |
510 | 505 | | |
511 | 506 | | |
512 | | - | |
| 507 | + | |
| 508 | + | |
513 | 509 | | |
514 | 510 | | |
515 | 511 | | |
| |||
0 commit comments