From: Shawn Bohrer <shawn.bohrer@gmail.com>
To: Frank Lichtenheld <frank@lichtenheld.de>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH] Make git-clean a builtin
Date: Sat, 6 Oct 2007 20:13:31 -0500 [thread overview]
Message-ID: <20071007011331.GC5642@mediacenter.austin.rr.com> (raw)
In-Reply-To: <20071006215253.GX31659@planck.djpig.de>
On Sat, Oct 06, 2007 at 11:52:53PM +0200, Frank Lichtenheld wrote:
> On Sat, Oct 06, 2007 at 03:54:06PM -0500, Shawn Bohrer wrote:
> > +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...
Agreed, I'm not sure what I was thinking there.
> > + 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?
If p == NULL then the path didn't have a EOL character. This shouldn't
ever really happen since fgets() leaves the EOL character as part of the
string, and it is processing the output of git-ls-files which will
provide one path per line. If it does happen for some reason then
either we will happily remove the file/directory, or if the path is
garbage then we will simply fail to remove anything.
> > + 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.
Yes, though unlikely I agree this wasn't very smart in the first place
so I fixed it and will send reworked patch soon.
--
Shawn
next prev parent reply other threads:[~2007-10-07 1:12 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-06 20:54 [PATCH] Make git-clean a builtin Shawn Bohrer
2007-10-06 21:52 ` Frank Lichtenheld
2007-10-07 1:13 ` Shawn Bohrer [this message]
2007-10-08 2:04 ` Jeff King
2007-10-08 2:08 ` Jeff King
2007-10-08 2:17 ` Linus Torvalds
2007-10-08 2:22 ` Jeff King
2007-10-08 6:37 ` Johannes Sixt
2007-10-08 18:27 ` Linus Torvalds
-- strict thread matches above, loose matches on Subject: below --
2007-10-07 1:17 Shawn Bohrer
2007-10-07 1:31 ` Linus Torvalds
2007-10-07 15:41 ` Shawn Bohrer
2007-10-07 16:42 ` rae l
2007-10-07 16:38 ` Johannes Schindelin
2007-10-07 23:57 Shawn Bohrer
2007-10-08 3:57 ` Johannes Schindelin
2007-11-04 19:02 [RFC] Second attempt at making " Shawn Bohrer
2007-11-04 19:02 ` [PATCH] Add more tests for git-clean Shawn Bohrer
2007-11-04 19:02 ` [PATCH] Make git-clean a builtin Shawn Bohrer
2007-11-04 19:41 ` Pierre Habouzit
2007-11-05 21:14 ` Junio C Hamano
2007-11-05 22:10 ` Carlos Rica
2007-11-05 23:54 ` Junio C Hamano
2007-11-06 5:05 ` Shawn Bohrer
2007-11-06 5:30 ` Junio C Hamano
2007-11-07 5:18 Shawn Bohrer
2007-11-07 11:10 ` Johannes Schindelin
2007-11-07 13:29 ` Bill Lear
2007-11-07 14:17 ` Johannes Schindelin
2007-11-07 14:45 ` Matthieu Moy
2007-11-07 19:46 ` Jon Loeliger
2007-11-10 22:43 ` Miles Bader
2007-11-07 14:54 ` Shawn Bohrer
2007-11-07 15:04 ` Johannes Schindelin
2007-11-07 20:51 ` Brian Downing
2007-11-07 21:49 ` Junio C Hamano
2007-11-07 20:42 ` Junio C Hamano
2007-11-08 5:37 ` Shawn Bohrer
2007-11-12 1:48 Shawn Bohrer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071007011331.GC5642@mediacenter.austin.rr.com \
--to=shawn.bohrer@gmail.com \
--cc=frank@lichtenheld.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.