Index: src/os_unix.c ================================================================== --- src/os_unix.c +++ src/os_unix.c @@ -549,10 +549,19 @@ if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName; } return 0; } +/* +** Do not accept any file descriptor less than this value, in order to avoid +** opening database file using file descriptors that are commonly used for +** standard input, output, and error. +*/ +#ifndef SQLITE_MINIMUM_FILE_DESCRIPTOR +# define SQLITE_MINIMUM_FILE_DESCRIPTOR 3 +#endif + /* ** Invoke open(). Do so multiple times, until it either succeeds or ** fails for some reason other than EINTR. ** ** If the file creation mode "m" is 0 then set it to the default for @@ -579,11 +588,11 @@ #endif if( fd<0 ){ if( errno==EINTR ) continue; break; } - if( fd>2 ) break; + if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break; osClose(fd); sqlite3_log(SQLITE_WARNING, "attempt to open \"%s\" as file descriptor %d", z, fd); fd = -1; if( osOpen("/dev/null", f, m)<0 ) break;