Re: [BUGS] COPY when 'filename' is a directory - Mailing list pgsql-patches

From Tom Lane
Subject Re: [BUGS] COPY when 'filename' is a directory
Date
Msg-id 27606.1014514067@sss.pgh.pa.us
Whole thread Raw
In response to Re: [BUGS] COPY when 'filename' is a directory  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: [BUGS] COPY when 'filename' is a directory  (Brent Verner <brent@rcfile.org>)
Re: [BUGS] COPY when 'filename' is a directory  (Brent Verner <brent@rcfile.org>)
List pgsql-patches
Bruce Momjian <pgman@candle.pha.pa.us> writes:
>           {
> +       struct stat st;
>               fp = AllocateFile(filename, PG_BINARY_R);
> !
> !       if (fp == NULL)
>                   elog(ERROR, "COPY command, running in backend with "
>                        "effective uid %d, could not open file '%s' for "
>                        "reading.  Errno = %s (%d).",
>                        (int) geteuid(), filename, strerror(errno), errno);
> +
> +       fstat(fileno(fp),&st);
> +       if( S_ISDIR(st.st_mode) ){
> +         fclose(fp);
> +         elog(ERROR,"COPY: %s is a directory.",filename);
> +       }

This coding is WRONG.  You do not use fclose() to release a file
opened with AllocateFile.

[ several other instances of same error in patch... ]

            regards, tom lane

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Cygwin plperl patch
Next
From: Brent Verner
Date:
Subject: Re: [BUGS] COPY when 'filename' is a directory