Commit ad2dd5b
commit-graph.c: remove path normalization, comparison
As of the previous patch, all calls to 'commit-graph.c' functions which
perform path normalization (for e.g., 'get_commit_graph_filename()') are
of the form 'ctx->odb->path', which is always in normalized form.
Now that there are no callers passing non-normalized paths to these
functions, ensure that future callers are bound by the same restrictions
by making these functions take a 'struct object_directory *' instead of
a 'const char *'. To match, replace all calls with arguments of the form
'ctx->odb->path' with 'ctx->odb' To recover the path, functions that
perform path manipulation simply use 'odb->path'.
Further, avoid string comparisons with arguments of the form
'odb->path', and instead prefer raw pointer comparisons, which
accomplish the same effect, but are far less brittle.
This has a pleasant side-effect of making these functions much more
robust to paths that cannot be normalized by 'normalize_path_copy()',
i.e., because they are outside of the current working directory.
For example, prior to this patch, Valgrind reports that the following
uninitialized memory read [1]:
$ ( cd t && GIT_DIR=../.git valgrind git rev-parse HEAD^ )
because 'normalize_path_copy()' can't normalize '../.git' (since it's
relative to but above of the current working directory) [2].
By using a 'struct object_directory *' directly,
'get_commit_graph_filename()' does not need to normalize, because all
paths are relative to the current working directory since they are
always read from the '->path' of an object directory.
[1]: https://lore.kernel.org/git/20191027042116.GA5801@sigill.intra.peff.net.
[2]: The bug here is that 'get_commit_graph_filename()' returns the
result of 'normalize_path_copy()' without checking the return
value.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>1 parent 13c2499 commit ad2dd5b
File tree
4 files changed
+24
-33
lines changed- builtin
- t/helper
4 files changed
+24
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
| 49 | + | |
54 | 50 | | |
55 | 51 | | |
56 | | - | |
| 52 | + | |
57 | 53 | | |
58 | 54 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 55 | + | |
| 56 | + | |
66 | 57 | | |
67 | 58 | | |
68 | | - | |
| 59 | + | |
69 | 60 | | |
70 | | - | |
| 61 | + | |
71 | 62 | | |
72 | 63 | | |
73 | 64 | | |
| |||
330 | 321 | | |
331 | 322 | | |
332 | 323 | | |
333 | | - | |
| 324 | + | |
334 | 325 | | |
335 | 326 | | |
336 | 327 | | |
| |||
381 | 372 | | |
382 | 373 | | |
383 | 374 | | |
384 | | - | |
| 375 | + | |
385 | 376 | | |
386 | 377 | | |
387 | 378 | | |
| |||
414 | 405 | | |
415 | 406 | | |
416 | 407 | | |
417 | | - | |
| 408 | + | |
418 | 409 | | |
419 | 410 | | |
420 | 411 | | |
| |||
1375 | 1366 | | |
1376 | 1367 | | |
1377 | 1368 | | |
1378 | | - | |
| 1369 | + | |
1379 | 1370 | | |
1380 | 1371 | | |
1381 | 1372 | | |
| |||
1386 | 1377 | | |
1387 | 1378 | | |
1388 | 1379 | | |
1389 | | - | |
| 1380 | + | |
1390 | 1381 | | |
1391 | 1382 | | |
1392 | 1383 | | |
| |||
1474 | 1465 | | |
1475 | 1466 | | |
1476 | 1467 | | |
1477 | | - | |
| 1468 | + | |
1478 | 1469 | | |
1479 | 1470 | | |
1480 | 1471 | | |
| |||
1510 | 1501 | | |
1511 | 1502 | | |
1512 | 1503 | | |
1513 | | - | |
| 1504 | + | |
1514 | 1505 | | |
1515 | 1506 | | |
1516 | 1507 | | |
1517 | 1508 | | |
1518 | | - | |
| 1509 | + | |
1519 | 1510 | | |
1520 | 1511 | | |
1521 | 1512 | | |
| |||
1557 | 1548 | | |
1558 | 1549 | | |
1559 | 1550 | | |
1560 | | - | |
| 1551 | + | |
1561 | 1552 | | |
1562 | 1553 | | |
1563 | 1554 | | |
| |||
1569 | 1560 | | |
1570 | 1561 | | |
1571 | 1562 | | |
1572 | | - | |
| 1563 | + | |
1573 | 1564 | | |
1574 | 1565 | | |
1575 | | - | |
| 1566 | + | |
1576 | 1567 | | |
1577 | 1568 | | |
1578 | 1569 | | |
| |||
1723 | 1714 | | |
1724 | 1715 | | |
1725 | 1716 | | |
1726 | | - | |
| 1717 | + | |
1727 | 1718 | | |
1728 | 1719 | | |
1729 | 1720 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
0 commit comments