git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 3/9] reftable/stack: fix parameter validation when compacting range

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 2, 2024, 05:21 UTC
Message-ID
<Zbx744Uln_UyyyYi@tanuki>
In-Reply-To
<87o7d0p38k.fsf@iotcl.com>
On Thu, Feb 01, 2024 at 05:15:14PM +0100, Toon Claes wrote:
Show 30 quoted lines
> 
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > diff --git a/reftable/stack.c b/reftable/stack.c
> > index d084823a92..b6b24c90bf 100644
> > --- a/reftable/stack.c
> > +++ b/reftable/stack.c
> > @@ -1146,12 +1146,14 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last,
> >  done:
> >  	free_names(delete_on_success);
> >
> > -	listp = subtable_locks;
> > -	while (*listp) {
> > -		unlink(*listp);
> > -		listp++;
> > +	if (subtable_locks) {
> > +		listp = subtable_locks;
> > +		while (*listp) {
> > +			unlink(*listp);
> > +			listp++;
> > +		}
> > +		free_names(subtable_locks);
> >  	}
> > -	free_names(subtable_locks);
> >  	if (lock_file_fd >= 0) {
> >  		close(lock_file_fd);
> >  		lock_file_fd = -1;
> 
> Technically, this change is not needed, because `free_names()` deals
> with NULL pointers already.

It actually is, but it's easy to miss. The reason why I've started to guard the code isn't `free_names()`. It's rather the `while (*listp)`, where we dereference `listp` unconditionally. Before these refactorings, `subtable_locks` would never be `NULL`. Now it can be though, and in that case we would be dereferencing a `NULL` pointer.

Patrick
Previous: Toon ClaesNext: Patrick Steinhardt
Message 23 of 40 in “reftable: code style improvements”
  1. 0/9 reftable: code style improvementsPatrick Steinhardt, Jan 31, 2024
  2. 1/9 reftable: introduce macros to grow arraysPatrick Steinhardt, Jan 31, 2024
  3. Eric SunshineJan 31, 2024
  4. Junio C HamanoJan 31, 2024
  5. Patrick SteinhardtFeb 1, 2024
  6. Junio C HamanoFeb 1, 2024
  7. 2/9 reftable: introduce macros to allocate arraysPatrick Steinhardt, Jan 31, 2024
  8. 3/9 reftable/stack: fix parameter validation when compacting rangePatrick Steinhardt, Jan 31, 2024
  9. 4/9 reftable/stack: index segments with `size_t`Patrick Steinhardt, Jan 31, 2024
  10. 5/9 reftable/stack: use `size_t` to track stack slices during compactionPatrick Steinhardt, Jan 31, 2024
  11. 6/9 reftable/stack: use `size_t` to track stack lengthPatrick Steinhardt, Jan 31, 2024
  12. 7/9 reftable/merged: refactor seeking of recordsPatrick Steinhardt, Jan 31, 2024
  13. Eric SunshineJan 31, 2024
  14. 8/9 reftable/merged: refactor initialization of iteratorsPatrick Steinhardt, Jan 31, 2024
  15. 9/9 reftable/record: improve semantics when initializing recordsPatrick Steinhardt, Jan 31, 2024
  16. 0/9 reftable: code style improvementsPatrick Steinhardt, Feb 1, 2024
  17. 1/9 reftable: introduce macros to grow arraysPatrick Steinhardt, Feb 1, 2024
  18. 2/9 reftable: introduce macros to allocate arraysPatrick Steinhardt, Feb 1, 2024
  19. Karthik NayakFeb 5, 2024
  20. Patrick SteinhardtFeb 6, 2024
  21. 3/9 reftable/stack: fix parameter validation when compacting rangePatrick Steinhardt, Feb 1, 2024
  22. Toon ClaesFeb 1, 2024
  23. Patrick SteinhardtFeb 2, 2024
  24. 4/9 reftable/stack: index segments with `size_t`Patrick Steinhardt, Feb 1, 2024
  25. 5/9 reftable/stack: use `size_t` to track stack slices during compactionPatrick Steinhardt, Feb 1, 2024
  26. 6/9 reftable/stack: use `size_t` to track stack lengthPatrick Steinhardt, Feb 1, 2024
  27. 7/9 reftable/merged: refactor seeking of recordsPatrick Steinhardt, Feb 1, 2024
  28. 8/9 reftable/merged: refactor initialization of iteratorsPatrick Steinhardt, Feb 1, 2024
  29. 9/9 reftable/record: improve semantics when initializing recordsPatrick Steinhardt, Feb 1, 2024
  30. 0/9 reftable: code style improvementsPatrick Steinhardt, Feb 6, 2024
  31. 1/9 reftable: introduce macros to grow arraysPatrick Steinhardt, Feb 6, 2024
  32. 2/9 reftable: introduce macros to allocate arraysPatrick Steinhardt, Feb 6, 2024
  33. 3/9 reftable/stack: fix parameter validation when compacting rangePatrick Steinhardt, Feb 6, 2024
  34. 4/9 reftable/stack: index segments with `size_t`Patrick Steinhardt, Feb 6, 2024
  35. 5/9 reftable/stack: use `size_t` to track stack slices during compactionPatrick Steinhardt, Feb 6, 2024
  36. 6/9 reftable/stack: use `size_t` to track stack lengthPatrick Steinhardt, Feb 6, 2024
  37. 7/9 reftable/merged: refactor seeking of recordsPatrick Steinhardt, Feb 6, 2024
  38. 8/9 reftable/merged: refactor initialization of iteratorsPatrick Steinhardt, Feb 6, 2024
  39. 9/9 reftable/record: improve semantics when initializing recordsPatrick Steinhardt, Feb 6, 2024
  40. Karthik NayakFeb 6, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.