From 5b290ada658624192095d97819c7910dcc42476e Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Sat, 14 Aug 2004 10:51:00 +0000 Subject: [PATCH] * extfs.c (extfs_init): Fix possible off-by-one buffer underflow for empty lines in extfs.ini. --- vfs/ChangeLog | 7 ++++++- vfs/extfs.c | 21 ++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/vfs/ChangeLog b/vfs/ChangeLog index 959a7b553..1e7d87256 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,3 +1,8 @@ +2004-08-14 Andrew V. Samoilov + + * extfs.c (extfs_init): Fix possible off-by-one buffer underflow + for empty lines in extfs.ini. + 2004-06-14 Pavel Roskin * tar.c: Eliminate struct hstat, use stack arguments instead. @@ -67,7 +72,7 @@ 2003-11-14 Andrew V. Samoilov - * undelfs.c (undelfs_loaddel): Use g_try_malloc()/g_try_relloc() + * undelfs.c (undelfs_loaddel): Use g_try_malloc()/g_try_realloc() since we want to recover and not abort the program if we don't have enough memory. (com_err): Fix implementation. diff --git a/vfs/extfs.c b/vfs/extfs.c index f624d54ba..66f2cdd71 100644 --- a/vfs/extfs.c +++ b/vfs/extfs.c @@ -1249,6 +1249,7 @@ static int extfs_init (struct vfs_class *me) { FILE *cfg; char *mc_extfsini; + char key[256]; mc_extfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini"); cfg = fopen (mc_extfsini, "r"); @@ -1257,19 +1258,15 @@ static int extfs_init (struct vfs_class *me) * UI is not initialized at this time and message would not * appear on screen. */ if (!cfg) { - fprintf(stderr, _("Warning: file %s not found\n"), mc_extfsini); + fprintf (stderr, _("Warning: file %s not found\n"), mc_extfsini); g_free (mc_extfsini); return 0; } extfs_no = 0; - while ( extfs_no < MAXEXTFS ) { - char key[256]; + while (extfs_no < MAXEXTFS && fgets (key, sizeof (key), cfg)) { char *c; - if (!fgets( key, sizeof (key)-1, cfg )) - break; - /* Handle those with a trailing ':', those flag that the * file system does not require an archive to work */ @@ -1281,23 +1278,21 @@ static int extfs_init (struct vfs_class *me) g_free (mc_extfsini); return 0; } - if (*key == '#') + if (*key == '#' || *key == '\n') continue; if ((c = strchr (key, '\n'))){ - *c = 0; + *c-- = 0; + } else { /* Last line without newline or strlen (key) > 255 */ c = &key [strlen (key) - 1]; - } else { - c = key; } extfs_need_archive [extfs_no] = !(*c == ':'); if (*c == ':') - *c = 0; + *c = 0; if (!(*key)) continue; - extfs_prefixes [extfs_no] = g_strdup (key); - extfs_no++; + extfs_prefixes [extfs_no++] = g_strdup (key); } fclose(cfg); g_free (mc_extfsini); -- 2.11.4.GIT