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

Re: [PATCH] Make git-clean a builtin

From
Frank Lichtenheld <frank@lichtenheld.de>
Date
Oct 6, 2007, 21:52 UTC
Message-ID
<20071006215253.GX31659@planck.djpig.de>
In-Reply-To
<11917040461528-git-send-email-shawn.bohrer@gmail.com>
On Sat, Oct 06, 2007 at 03:54:06PM -0500, Shawn Bohrer wrote:
Show 21 quoted lines
> +static int remove_directory(const char *path)
> +{
> +	DIR *d;
> +	struct dirent *dir;
> +	d = opendir(path);
> +	if (d) {
> +		chdir(path);
> +		while ((dir = readdir(d)) != NULL) {
> +			if(strcmp( dir->d_name, ".") == 0 ||
> +			   strcmp( dir->d_name, ".." ) == 0 )
> +				continue;
> +			if (dir->d_type == DT_DIR)
> +				remove_directory(dir->d_name);
> +			else
> +				unlink(dir->d_name);
> +		}
> +	}
> +	closedir(d);
> +	chdir("..");
> +	return rmdir(path);
> +}

The unconditional chdir(..) after the conditional chdir(path) seems like asking for trouble to me...

Show 6 quoted lines
> +	while (fgets(path, sizeof(path), cmd_fout) != NULL) {
> +		struct stat st;
> +		char *p;
> +		p = strrchr(path, '\n');
> +		if ( p != NULL )
> +			*p = '\0';

What happens in case p == NULL? It simply tries to remove the partial path?

> +	fclose(cmd_fout);
> +	finish_command(&cmd);
> +	if (!ignored && !access(git_path("info/exclude"), F_OK))
> +		free(buf);

There is a race condition here of the value of access() changes between the two calls. Not one likely to trigger but it should be easy to avoid alltogether.

> +	free(argv_ls_files);
> +	return 0;
> +}
Gruesse,
-- 
Frank Lichtenheld <frank@lichtenheld.de>
www: http://www.djpig.de/
Previous: Shawn BohrerNext: Shawn Bohrer
Message 2 of 9 in “Make git-clean a builtin”
  1. Make git-clean a builtinShawn Bohrer, Oct 6, 2007
  2. Frank LichtenheldOct 6, 2007
  3. Shawn BohrerOct 7, 2007
  4. Jeff KingOct 8, 2007
  5. Jeff KingOct 8, 2007
  6. Linus TorvaldsOct 8, 2007
  7. Jeff KingOct 8, 2007
  8. Johannes SixtOct 8, 2007
  9. Linus TorvaldsOct 8, 2007

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.