summaryrefslogtreecommitdiff
path: root/dist/sqlite3.c
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2014-09-10 13:14:28 -0700
committerLorDClockaN <davor@losinj.com>2014-09-28 17:40:58 +0200
commit70920d9f18564feacb4132bfaa4bcea3528a70a4 (patch)
treef6eafe3dce6f3b870bf4f634a3c7f052bd8c9c84 /dist/sqlite3.c
parentce91dbed6425fbe874239810e6b1d7b93a3b6564 (diff)
Fix world-readable permissions due to sqlite race conditionkitkat
Existing code uses umask() to temporarily modify the file permissions for open(). A race condition can occur where a second thread reads in the temporary value, saves it, and then restores the file to the temporary value resulting in world-readable permissions. Backporting a known fix: http://www.sqlite.org/src/info/6c4c2b7dba Bug: 15288755 Change-Id: I89779f3a5ba0bec181d6614b29b1e26ea4f4f049
Diffstat (limited to 'dist/sqlite3.c')
-rwxr-xr-xdist/sqlite3.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/dist/sqlite3.c b/dist/sqlite3.c
index 28f9487..0f60f54 100755
--- a/dist/sqlite3.c
+++ b/dist/sqlite3.c
@@ -25434,11 +25434,7 @@ static struct unix_syscall {
aSyscall[13].pCurrent)
#endif
-#if SQLITE_ENABLE_LOCKING_STYLE
{ "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
-#else
- { "fchmod", (sqlite3_syscall_ptr)0, 0 },
-#endif
#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
@@ -25463,9 +25459,6 @@ static struct unix_syscall {
{ "fchown", (sqlite3_syscall_ptr)fchown, 0 },
#define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
- { "umask", (sqlite3_syscall_ptr)umask, 0 },
-#define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
-
}; /* End of the overrideable system calls */
/*
@@ -25569,20 +25562,20 @@ static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){
** recover the hot journals.
*/
static int robust_open(const char *z, int f, mode_t m){
- int rc;
- mode_t m2;
- mode_t origM = 0;
- if( m==0 ){
- m2 = SQLITE_DEFAULT_FILE_PERMISSIONS;
- }else{
- m2 = m;
- origM = osUmask(0);
- }
- do{ rc = osOpen(z,f,m2); }while( rc<0 && errno==EINTR );
- if( m ){
- osUmask(origM);
+ int fd;
+ mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS;
+ do{
+ fd = osOpen(z,f,m2);
+ }while( fd<0 && errno==EINTR );
+ if( fd>=0 ){
+ if( m!=0 ){
+ struct stat statbuf;
+ if( osFstat(fd, &statbuf)==0 && (statbuf.st_mode&0777)!=m ){
+ osFchmod(fd, m);
+ }
+ }
}
- return rc;
+ return fd;
}
/*