/ Check-in [d9d92781]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Avoid even trying to open a SHM file read/write in WAL mode if we know that the file is read-only. This avoids scare security log messages.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA3-256: d9d927814019f6c562eca198aca10f407aae423ea0a9f82c789298b77be8c187
User & Date: drh 2017-07-07 20:33:36
Context
2017-07-07
22:39
Fix test cases in wal2.test due to the fact that Darwin checks to see if the SHM file is writable before attempting to open in read/write. check-in: 6b618b18 user: drh tags: apple-osx
20:33
Avoid even trying to open a SHM file read/write in WAL mode if we know that the file is read-only. This avoids scare security log messages. check-in: d9d92781 user: drh tags: apple-osx
2017-06-27
16:48
Merge latest trunk changes with this branch. check-in: 2b095406 user: dan tags: apple-osx
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

5053
5054
5055
5056
5057
5058
5059
5060







5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
        goto shm_open_err;
      }
    }

    if( pInode->bProcessLock==0 ){
      int openFlags = O_RDWR | O_CREAT;
      int fd;                     /* File descriptor for *-shm file */
      if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){







        openFlags = O_RDONLY;
        pShmNode->isReadonly = 1;
      }
      fd = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777));

      /* If it was not possible to open the *-shm file in read/write mode,
      ** and the database file itself has been opened in read-only mode,
      ** try to open the *-shm file in read-only mode as well. Even if the
      ** database connection is read-only, it is still better to try opening
      ** the *-shm file in read/write mode first, as the same file descriptor
      ** may be also be used by a read/write database connection.  */
#if defined(SQLITE_ENABLE_PERSIST_WAL)&&(SQLITE_ENABLE_LOCKING_STYLE \
    || defined(__APPLE__))
      if( fd<0 && errno!=EISDIR && pShmNode->isReadonly==0 
       && (pDbFd->openFlags & O_RDWR)!=O_RDWR
      ){
        fd = robust_open(zShmFilename, O_RDONLY, (sStat.st_mode&0777));
        pShmNode->isReadonly = 1;
      }
#endif
      if( fd<0 ){







|
>
>
>
>
>
>
>













|







5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
        goto shm_open_err;
      }
    }

    if( pInode->bProcessLock==0 ){
      int openFlags = O_RDWR | O_CREAT;
      int fd;                     /* File descriptor for *-shm file */
      if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0)
#ifdef __APPLE__
       /* On MacOS and iOS, avoid even trying to open a read-only SHM file
       ** for writing, because doing so generates scary log messages */
       || (osAccess(zShmFilename, R_OK|W_OK)!=0
            && (errno==EPERM || errno==EACCES))
#endif
      ){
        openFlags = O_RDONLY;
        pShmNode->isReadonly = 1;
      }
      fd = robust_open(zShmFilename, openFlags, (sStat.st_mode&0777));

      /* If it was not possible to open the *-shm file in read/write mode,
      ** and the database file itself has been opened in read-only mode,
      ** try to open the *-shm file in read-only mode as well. Even if the
      ** database connection is read-only, it is still better to try opening
      ** the *-shm file in read/write mode first, as the same file descriptor
      ** may be also be used by a read/write database connection.  */
#if defined(SQLITE_ENABLE_PERSIST_WAL)&&(SQLITE_ENABLE_LOCKING_STYLE \
    || defined(__APPLE__))
      if( fd<0 && (errno==EPERM || errno==EACCES) && pShmNode->isReadonly==0 
       && (pDbFd->openFlags & O_RDWR)!=O_RDWR
      ){
        fd = robust_open(zShmFilename, O_RDONLY, (sStat.st_mode&0777));
        pShmNode->isReadonly = 1;
      }
#endif
      if( fd<0 ){