From befdf6d46a30c7d0d1befe8bf127b8229f3ceeca Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 21 Sep 2008 19:48:39 +0200 Subject: 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. --- src/libmpdclient.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') 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; -- cgit v1.2.3