bpd: fix bug in bounds check of current song index

The songs are indexed starting from zero for the play command, however
the bound check was off by one. An index matching the length of the
playlist would crash the server instead of responding with an error
message over the protocol.
This commit is contained in:
Carl Suster 2019-04-01 17:41:25 +11:00
parent 0c3a63ef9f
commit a4fe6875a1
2 changed files with 6 additions and 3 deletions

View file

@ -569,7 +569,7 @@ class BaseServer(object):
"""Begin playback, possibly at a specified playlist index."""
index = cast_arg(int, index)
if index < -1 or index > len(self.playlist):
if index < -1 or index >= len(self.playlist):
raise ArgumentIndexError()
if index == -1: # No index specified: start where we are.

View file

@ -525,14 +525,17 @@ class BPDControlTest(BPDTestHelper):
def test_cmd_play(self):
with self.run_bpd() as client:
self._bpd_add(client, self.item1)
self._bpd_add(client, self.item1, self.item2)
responses = client.send_commands(
('status',),
('play',),
('status',))
('status',),
('play', '1'),
('currentsong',))
self._assert_ok(*responses)
self.assertEqual('stop', responses[0].data['state'])
self.assertEqual('play', responses[2].data['state'])
self.assertEqual('2', responses[4].data['Id'])
def test_cmd_next(self):
with self.run_bpd() as client: