playlist: fix buffer underflow when getting current song
The function moveSongInPlaylist() attempted to read the position of the current song, even if it was -1. Check that first. The same bug was in shufflePlaylist().
This commit is contained in:
@@ -963,7 +963,7 @@ enum playlist_result moveSongInPlaylist(unsigned from, int to)
|
|||||||
unsigned i;
|
unsigned i;
|
||||||
struct song *tmpSong;
|
struct song *tmpSong;
|
||||||
unsigned tmpId;
|
unsigned tmpId;
|
||||||
unsigned currentSong;
|
int currentSong;
|
||||||
|
|
||||||
if (from >= playlist.length)
|
if (from >= playlist.length)
|
||||||
return PLAYLIST_RESULT_BAD_RANGE;
|
return PLAYLIST_RESULT_BAD_RANGE;
|
||||||
@@ -979,9 +979,10 @@ enum playlist_result moveSongInPlaylist(unsigned from, int to)
|
|||||||
* (to < 0) => move to offset from current song
|
* (to < 0) => move to offset from current song
|
||||||
* (-playlist.length == to) => move to position BEFORE current song
|
* (-playlist.length == to) => move to position BEFORE current song
|
||||||
*/
|
*/
|
||||||
currentSong = playlist.order[playlist.current];
|
currentSong = playlist.current >= 0
|
||||||
|
? (int)playlist.order[playlist.current] : -1;
|
||||||
if (to < 0 && playlist.current >= 0) {
|
if (to < 0 && playlist.current >= 0) {
|
||||||
if (currentSong == from)
|
if ((unsigned)currentSong == from)
|
||||||
/* no-op, can't be moved to offset of itself */
|
/* no-op, can't be moved to offset of itself */
|
||||||
return PLAYLIST_RESULT_SUCCESS;
|
return PLAYLIST_RESULT_SUCCESS;
|
||||||
to = (currentSong + abs(to)) % playlist.length;
|
to = (currentSong + abs(to)) % playlist.length;
|
||||||
@@ -990,7 +991,7 @@ enum playlist_result moveSongInPlaylist(unsigned from, int to)
|
|||||||
if (playlist_state == PLAYLIST_STATE_PLAY && playlist.queued >= 0) {
|
if (playlist_state == PLAYLIST_STATE_PLAY && playlist.queued >= 0) {
|
||||||
int queuedSong = playlist.order[playlist.queued];
|
int queuedSong = playlist.order[playlist.queued];
|
||||||
if (queuedSong == (int)from || queuedSong == to
|
if (queuedSong == (int)from || queuedSong == to
|
||||||
|| currentSong == from || (int)currentSong == to)
|
|| currentSong == (int)from || currentSong == to)
|
||||||
clearPlayerQueue();
|
clearPlayerQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1160,11 +1161,13 @@ void shufflePlaylist(void)
|
|||||||
|
|
||||||
if (playlist.length > 1) {
|
if (playlist.length > 1) {
|
||||||
if (playlist_state == PLAYLIST_STATE_PLAY) {
|
if (playlist_state == PLAYLIST_STATE_PLAY) {
|
||||||
if (playlist.queued >= 0)
|
if (playlist.queued >= 0) {
|
||||||
clearPlayerQueue();
|
clearPlayerQueue();
|
||||||
|
|
||||||
/* put current playing song first */
|
/* put current playing song first */
|
||||||
swapSongs(0, playlist.order[playlist.current]);
|
swapSongs(0, playlist.order[playlist.current]);
|
||||||
|
}
|
||||||
|
|
||||||
if (playlist.random) {
|
if (playlist.random) {
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; 0 != playlist.order[j]; j++) ;
|
for (j = 0; 0 != playlist.order[j]; j++) ;
|
||||||
|
Reference in New Issue
Block a user