Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit d4f30d0

Browse files
Fix world-readable permissions due to sqlite race condition
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
1 parent e6db643 commit d4f30d0

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

Diff for: dist/sqlite3.c

+13-20
Original file line numberDiff line numberDiff line change
@@ -25426,11 +25426,7 @@ static struct unix_syscall {
2542625426
aSyscall[13].pCurrent)
2542725427
#endif
2542825428

25429-
#if SQLITE_ENABLE_LOCKING_STYLE
2543025429
{ "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
25431-
#else
25432-
{ "fchmod", (sqlite3_syscall_ptr)0, 0 },
25433-
#endif
2543425430
#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
2543525431

2543625432
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
@@ -25455,9 +25451,6 @@ static struct unix_syscall {
2545525451
{ "fchown", (sqlite3_syscall_ptr)fchown, 0 },
2545625452
#define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
2545725453

25458-
{ "umask", (sqlite3_syscall_ptr)umask, 0 },
25459-
#define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
25460-
2546125454
}; /* End of the overrideable system calls */
2546225455

2546325456
/*
@@ -25561,20 +25554,20 @@ static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){
2556125554
** recover the hot journals.
2556225555
*/
2556325556
static int robust_open(const char *z, int f, mode_t m){
25564-
int rc;
25565-
mode_t m2;
25566-
mode_t origM = 0;
25567-
if( m==0 ){
25568-
m2 = SQLITE_DEFAULT_FILE_PERMISSIONS;
25569-
}else{
25570-
m2 = m;
25571-
origM = osUmask(0);
25572-
}
25573-
do{ rc = osOpen(z,f,m2); }while( rc<0 && errno==EINTR );
25574-
if( m ){
25575-
osUmask(origM);
25557+
int fd;
25558+
mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS;
25559+
do{
25560+
fd = osOpen(z,f,m2);
25561+
}while( fd<0 && errno==EINTR );
25562+
if( fd>=0 ){
25563+
if( m!=0 ){
25564+
struct stat statbuf;
25565+
if( osFstat(fd, &statbuf)==0 && (statbuf.st_mode&0777)!=m ){
25566+
osFchmod(fd, m);
25567+
}
25568+
}
2557625569
}
25577-
return rc;
25570+
return fd;
2557825571
}
2557925572

2558025573
/*

0 commit comments

Comments
 (0)