[vlc-devel] commit: config: if read-only, refuse to save the configuration ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sun Jul 12 20:08:45 CEST 2009
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 12 21:04:21 2009 +0300| [eb54a41c0f2150d7d33e855bb36899fedaf0743d] | committer: Rémi Denis-Courmont
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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=eb54a41c0f2150d7d33e855bb36899fedaf0743d
---
src/config/file.c | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/config/file.c b/src/config/file.c
index 10a483e..9417e55 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 );
More information about the vlc-devel
mailing list