From eb54a41c0f2150d7d33e855bb36899fedaf0743d Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sun, 12 Jul 2009 21:04:21 +0300 Subject: [PATCH] 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. --- src/config/file.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 ); -- 2.39.2