From: Max Kellermann Date: Sun, 21 Sep 2008 17:48:39 +0000 (+0200) Subject: libmpdclient: check connection->sock >= 0 X-Git-Tag: v0.12_alpha1~205 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=befdf6d46a30c7d0d1befe8bf127b8229f3ceeca;p=ncmpc.git 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. --- diff --git a/src/libmpdclient.c b/src/libmpdclient.c index 0f2b1b5..2b4a52c 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;