aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-21 19:48:39 +0200
committerMax Kellermann <max@duempel.org>2008-09-21 21:51:01 +0200
commitbefdf6d46a30c7d0d1befe8bf127b8229f3ceeca (patch)
tree0be9fe9fd1b7b928c9b67124ba9a2ecafa136e24 /src
parent61053ab09a52c4a0ca36ed4e7eb01cc8a26463d9 (diff)
downloadmpd-befdf6d46a30c7d0d1befe8bf127b8229f3ceeca.tar.gz
mpd-befdf6d46a30c7d0d1befe8bf127b8229f3ceeca.tar.xz
mpd-befdf6d46a30c7d0d1befe8bf127b8229f3ceeca.zip
libmpdclient: check connection->sock >= 0
mpd_wait() must not be called when the socket is dead; add an assertion there. In mpd_recv(), add a run-time check.
Diffstat (limited to 'src')
-rw-r--r--src/libmpdclient.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libmpdclient.c b/src/libmpdclient.c
index 0f2b1b503..2b4a52c85 100644
--- a/src/libmpdclient.c
+++ b/src/libmpdclient.c
@@ -213,6 +213,8 @@ static int mpd_wait(mpd_Connection *connection)
fd_set fds;
int ret;
+ assert(connection->sock >= 0);
+
while (1) {
tv = connection->timeout;
FD_ZERO(&fds);
@@ -265,6 +267,14 @@ static int mpd_recv(mpd_Connection *connection)
assert(connection->buflen <= sizeof(connection->buffer));
assert(connection->bufstart <= connection->buflen);
+ if (connection->sock < 0) {
+ strcpy(connection->errorStr, "not connected");
+ connection->error = MPD_ERROR_CONNCLOSED;
+ connection->doneProcessing = 1;
+ connection->doneListOk = 0;
+ return -1;
+ }
+
if (connection->buflen >= sizeof(connection->buffer)) {
/* delete consumed data from beginning of buffer */
connection->buflen -= connection->bufstart;