Re: [PATCH] opening files in remote.c should ensure it is opening a file
- From
- Morten Welinder <mwelinder@gmail.com>
- Date
- Feb 8, 2008, 20:15 UTC
- Message-ID
- <118833cc0802081215t380587f6w7b5c0aba66a55799@mail.gmail.com>
- In-Reply-To
- <20080208174654.2e9e679c@pc09.procura.nl>
Show 8 quoted lines
> +/* Helper function to ensure that we are opening a file and not a directory */
> +static FILE *open_file(char *full_path)
> +{
> + struct stat st_buf;
> + if (stat(full_path, &st_buf) || !S_ISREG(st_buf.st_mode))
> + return NULL;
> + return (fopen(full_path, "r"));
> +}That looks wrong. stat+fopen has a pointless race condition that open+fstat+fdopen would not have.
Morten