summaryrefslogtreecommitdiff
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
parent557633592ac85d52333134608d66f2b41091a0a6 (diff)
downloadrockbox-2459d23d0b224cea888e194bc2e6b82958d1461d.tar.gz
rockbox-2459d23d0b224cea888e194bc2e6b82958d1461d.zip
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
-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)
1176 int buflen; 1176 int buflen;
1177 int nread; 1177 int nread;
1178 int total_read = 0; 1178 int total_read = 0;
1179 int control_file_size = 0;
1179 bool first = true; 1180 bool first = true;
1180 bool sorted = true; 1181 bool sorted = true;
1181 1182
@@ -1205,6 +1206,13 @@ int playlist_resume(void)
1205 } 1206 }
1206 playlist->control_created = true; 1207 playlist->control_created = true;
1207 1208
1209 control_file_size = filesize(playlist->control_fd);
1210 if (control_file_size <= 0)
1211 {
1212 splash(HZ*2, true, str(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
1213 return -1;
1214 }
1215
1208 /* read a small amount first to get the header */ 1216 /* read a small amount first to get the header */
1209 nread = read(playlist->control_fd, buffer, 1217 nread = read(playlist->control_fd, buffer,
1210 PLAYLIST_COMMAND_SIZE<buflen?PLAYLIST_COMMAND_SIZE:buflen); 1218 PLAYLIST_COMMAND_SIZE<buflen?PLAYLIST_COMMAND_SIZE:buflen);
@@ -1492,10 +1500,15 @@ int playlist_resume(void)
1492 1500
1493 if (!newline || (exit_loop && count<nread)) 1501 if (!newline || (exit_loop && count<nread))
1494 { 1502 {
1503 if ((total_read + count) >= control_file_size)
1504 {
1505 /* no newline at end of control file */
1506 splash(HZ*2, true, str(LANG_PLAYLIST_CONTROL_INVALID));
1507 return -1;
1508 }
1509
1495 /* We didn't end on a newline or we exited loop prematurely. 1510 /* We didn't end on a newline or we exited loop prematurely.
1496 Either way, re-read the remainder. 1511 Either way, re-read the remainder. */
1497 NOTE: because of this, control file must always end with a
1498 newline */
1499 count = last_newline; 1512 count = last_newline;
1500 lseek(playlist->control_fd, total_read+count, SEEK_SET); 1513 lseek(playlist->control_fd, total_read+count, SEEK_SET);
1501 } 1514 }