summaryrefslogtreecommitdiff
path: root/apps/playlist.c
diff options
context:
space:
mode:
authorHardeep Sidhu <dyp@pobox.com>2004-07-14 18:02:38 +0000
committerHardeep Sidhu <dyp@pobox.com>2004-07-14 18:02:38 +0000
commit2459d23d0b224cea888e194bc2e6b82958d1461d (patch)
treebe419253515eb9a6f4f21be883122907d5b74099 /apps/playlist.c
parent557633592ac85d52333134608d66f2b41091a0a6 (diff)
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
Diffstat (limited to 'apps/playlist.c')
-rw-r--r--apps/playlist.c19
1 files changed, 16 insertions, 3 deletions
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<buflen?PLAYLIST_COMMAND_SIZE:buflen);
@@ -1492,10 +1500,15 @@ int playlist_resume(void)
if (!newline || (exit_loop && count<nread))
{
+ if ((total_read + count) >= 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);
}