]> git.sesse.net Git - vlc/commitdiff
config: if read-only, refuse to save the configuration
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 12 Jul 2009 18:04:21 +0000 (21:04 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 12 Jul 2009 18:04:21 +0000 (21:04 +0300)
This restores the pre-1.0.0 behaviour. With the atomic vlcrc update,
VLC managed to work-around a read-only vlcrc. Indeed, Linux (POSIX?)
allows renaming a file onto an existing read-only file, which is
then replaced (both content and meta-data). In principle, you should
put the containing directory in read-only mode to avoid this, but this
is inconvenient as .config/vlc contains other files.

src/config/file.c

index 10a483e1f08a36df72e5a2c1990215f9e0f164a6..9417e552bfa5a1d0ccf759167874b013d54e96aa 100644 (file)
@@ -430,12 +430,18 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
     file = config_OpenConfigFile( p_this );
     if( file != NULL )
     {
-        /* look for file size */
-        fseek( file, 0L, SEEK_END );
-        i_sizebuf = ftell( file );
-        fseek( file, 0L, SEEK_SET );
-        if( i_sizebuf >= LONG_MAX )
-            i_sizebuf = 0;
+        struct stat st;
+
+        /* Some users make vlcrc read-only to prevent changes.
+         * The atomic replacement scheme breaks this "feature",
+         * so we check for read-only by hand. */
+        if (fstat (fileno (file), &st)
+         || !(st.st_mode & S_IWUSR))
+        {
+            msg_Err (p_this, "configuration file is read-only");
+            goto error;
+        }
+        i_sizebuf = ( st.st_size < LONG_MAX ) ? st.st_size : 0;
     }
 
     p_bigbuffer = p_index = malloc( i_sizebuf+1 );