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

Re: [PATCH v4 1/2] refs: introduce reftable backend

From
Jeff King <peff@peff.net>
Date
Feb 7, 2024, 22:31 UTC
Message-ID
<20240207223120.GA537741@coredump.intra.peff.net>
In-Reply-To
<5de60d46bdccbfbf0a923abc2f45eda07f30c110.1707288261.git.ps@pks.im>
On Wed, Feb 07, 2024 at 08:20:31AM +0100, Patrick Steinhardt wrote:
Show 24 quoted lines
> +static int write_copy_table(struct reftable_writer *writer, void *cb_data)
> +{
> [...]
> +	/*
> +	 * Create the reflog entry for the newly created branch.
> +	 */
> +	ALLOC_GROW(logs, logs_nr + 1, logs_alloc);
> +	memset(&logs[logs_nr], 0, sizeof(logs[logs_nr]));
> +	fill_reftable_log_record(&logs[logs_nr]);
> +	logs[logs_nr].refname = (char *)arg->newname;
> +	logs[logs_nr].update_index = creation_ts;
> +	logs[logs_nr].value.update.message =
> +		xstrndup(arg->logmsg, arg->refs->write_options.block_size / 2);
> +	logs[logs_nr].value.update.new_hash = old_ref.value.val1;
> +	logs_nr++;
> +
> +	/*
> +	 * In addition to writing the reflog entry for the new branch, we also
> +	 * copy over all log entries from the old reflog. Last but not least,
> +	 * when renaming we also have to delete all the old reflog entries.
> +	 */
> +	ret = reftable_merged_table_seek_log(mt, &it, arg->oldname);
> +	if (ret < 0)
> +		return ret;

Should this last line be "goto done" as is used elsewhere in the function? Otherwise we are at least leaking the "logs" array (and possibly some of the other cleanup is important, too).

Show 8 quoted lines
> +	while (1) {
> +		ret = reftable_iterator_next_log(&it, &old_log);
> +		if (ret < 0)
> +			goto done;
> +		if (ret > 0 || strcmp(old_log.refname, arg->oldname)) {
> +			ret = 0;
> +			break;
> +		}

This "ret = 0" doesn't have any effect. We break out of the loop, and then...

Show 5 quoted lines
> +	}
> +
> +	ret = reftable_writer_add_logs(writer, logs, logs_nr);
> +	if (ret < 0)
> +		goto done;

...the first thing we do is write over it. I dunno if it's worth keeping as a maintenance precaution, though (if the code after the loop changed to omit that assignment, then setting "ret" would become important).

Both were noticed by Coverity (along with several other false positives).

-Peff
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 20 of 23 in “refs: introduce reftable backend”
  1. 0/2 refs: introduce reftable backendPatrick Steinhardt, Jan 30, 2024
  2. 1/2 refs: introduce reftable backendPatrick Steinhardt, Jan 30, 2024
  3. Karthik NayakFeb 1, 2024
  4. Patrick SteinhardtFeb 2, 2024
  5. Patrick SteinhardtFeb 2, 2024
  6. 2/2 ci: add jobs to test with the reftable backendPatrick Steinhardt, Jan 30, 2024
  7. Junio C HamanoJan 30, 2024
  8. 0/2 refs: introduce reftable backendPatrick Steinhardt, Feb 2, 2024
  9. 1/2 refs: introduce reftable backendPatrick Steinhardt, Feb 2, 2024
  10. 2/2 ci: add jobs to test with the reftable backendPatrick Steinhardt, Feb 2, 2024
  11. Karthik NayakFeb 2, 2024
  12. Junio C HamanoFeb 3, 2024
  13. Patrick SteinhardtFeb 4, 2024
  14. 0/2 refs: introduce reftable backendPatrick Steinhardt, Feb 5, 2024
  15. 1/2 refs: introduce reftable backendPatrick Steinhardt, Feb 5, 2024
  16. 2/2 ci: add jobs to test with the reftable backendPatrick Steinhardt, Feb 5, 2024
  17. Karthik NayakFeb 5, 2024
  18. 0/2 refs: introduce reftable backendPatrick Steinhardt, Feb 7, 2024
  19. 1/2 refs: introduce reftable backendPatrick Steinhardt, Feb 7, 2024
  20. Jeff KingFeb 7, 2024
  21. Patrick SteinhardtFeb 8, 2024
  22. Jeff KingFeb 15, 2024
  23. 2/2 ci: add jobs to test with the reftable backendPatrick Steinhardt, Feb 7, 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.