From: RĂ©mi Denis-Courmont Date: Sun, 12 Jul 2009 18:04:21 +0000 (+0300) Subject: config: if read-only, refuse to save the configuration X-Git-Tag: 1.1.0-ff~5007 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=eb54a41c0f2150d7d33e855bb36899fedaf0743d;p=vlc config: if read-only, refuse to save the configuration 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. --- diff --git a/src/config/file.c b/src/config/file.c index 10a483e1f0..9417e552bf 100644 --- a/src/config/file.c +++ b/src/config/file.c @@ -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 );