From 2459d23d0b224cea888e194bc2e6b82958d1461d Mon Sep 17 00:00:00 2001 From: Hardeep Sidhu Date: Wed, 14 Jul 2004 18:02:38 +0000 Subject: Abort resume if control file doesn't end with a newline. Fixes hang when resuming from a corrupt control file. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4882 a1c6a512-1295-4272-9138-f99709370657 --- apps/playlist.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'apps/playlist.c') diff --git a/apps/playlist.c b/apps/playlist.c index 29a8269dc3..cfa49d10ea 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -1176,6 +1176,7 @@ int playlist_resume(void) int buflen; int nread; int total_read = 0; + int control_file_size = 0; bool first = true; bool sorted = true; @@ -1205,6 +1206,13 @@ int playlist_resume(void) } playlist->control_created = true; + control_file_size = filesize(playlist->control_fd); + if (control_file_size <= 0) + { + splash(HZ*2, true, str(LANG_PLAYLIST_CONTROL_ACCESS_ERROR)); + return -1; + } + /* read a small amount first to get the header */ nread = read(playlist->control_fd, buffer, PLAYLIST_COMMAND_SIZE= control_file_size) + { + /* no newline at end of control file */ + splash(HZ*2, true, str(LANG_PLAYLIST_CONTROL_INVALID)); + return -1; + } + /* We didn't end on a newline or we exited loop prematurely. - Either way, re-read the remainder. - NOTE: because of this, control file must always end with a - newline */ + Either way, re-read the remainder. */ count = last_newline; lseek(playlist->control_fd, total_read+count, SEEK_SET); } -- cgit v1.2.3