1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Never leave an open file descriptor pointing into the middle of the

database file if the file descriptor number is 2 or less.

FossilOrigin-Name: 3426673e4659eb68dbd14a3e41d4620d748432db
This commit is contained in:
drh
2013-08-29 21:26:26 +00:00
parent 8bff07a55f
commit 0c9a8e345e
3 changed files with 14 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
C Restore\sfix\s[f15591f802],\swhich\swas\saccidentally\sclobbered\sby\sthe\sstat4\smerge. C Never\sleave\san\sopen\sfile\sdescriptor\spointing\sinto\sthe\smiddle\sof\sthe\ndatabase\sfile\sif\sthe\sfile\sdescriptor\snumber\sis\s2\sor\sless.
D 2013-08-29T14:56:14.988 D 2013-08-29T21:26:26.071
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -202,7 +202,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30
F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be
F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
F src/os_unix.c c27a14a05061e4e690bd3949dc0246bda35e399d F src/os_unix.c 94c7edbd75b0fb4fe477ccb3ba73a9bddaff9592
F src/os_win.c 26d752736dff0c7e4e384ab65b353cce1e7e19c5 F src/os_win.c 26d752736dff0c7e4e384ab65b353cce1e7e19c5
F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8
F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c
@@ -1109,7 +1109,10 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P c1152bdcbb5ac185f743015fff63769effa81b4b P d4b6ad3333cc3bad500c2ebf7a6ea552b6762b69
R ef3cf6caed80e05bf3e44c08e4ed05a0 R 97c4ef1fd2ecd2ffa8c4e00f7258a86d
U dan T *branch * overwrite-avoidance
Z a6b4620a23effa55e7cb7c1762a8f7ee T *sym-overwrite-avoidance *
T -sym-trunk *
U drh
Z c59ed8dd8c6786bd9c8e9cf6a1823506

View File

@@ -1 +1 @@
d4b6ad3333cc3bad500c2ebf7a6ea552b6762b69 3426673e4659eb68dbd14a3e41d4620d748432db

View File

@@ -588,6 +588,7 @@ static int robust_open(const char *z, int f, mode_t m){
osFchmod(fd, m); osFchmod(fd, m);
} }
} }
if( fd<=2 ) lseek(fd, 0, SEEK_END);
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
#endif #endif
@@ -3133,6 +3134,7 @@ static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
pBuf = (void*)(got + (char*)pBuf); pBuf = (void*)(got + (char*)pBuf);
} }
}while( got>0 ); }while( got>0 );
if( id->h<=2 ) lseek(id->h, 0, SEEK_END);
TIMER_END; TIMER_END;
OSTRACE(("READ %-3d %5d %7lld %llu\n", OSTRACE(("READ %-3d %5d %7lld %llu\n",
id->h, got+prior, offset-prior, TIMER_ELAPSED)); id->h, got+prior, offset-prior, TIMER_ELAPSED));
@@ -3232,6 +3234,7 @@ static int seekAndWriteFd(
rc = osWrite(fd, pBuf, nBuf); rc = osWrite(fd, pBuf, nBuf);
}while( rc<0 && errno==EINTR ); }while( rc<0 && errno==EINTR );
#endif #endif
if( fd<=2 ) lseek(fd, 0, SEEK_END);
TIMER_END; TIMER_END;
OSTRACE(("WRITE %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED)); OSTRACE(("WRITE %-3d %5d %7lld %llu\n", fd, rc, iOff, TIMER_ELAPSED));