Code

libmpdclient: check connection->sock >= 0
authorMax Kellermann <max@duempel.org>
Sun, 21 Sep 2008 17:48:39 +0000 (19:48 +0200)
committerMax Kellermann <max@duempel.org>
Sun, 21 Sep 2008 19:51:01 +0000 (21:51 +0200)
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

index 0f2b1b503d73b101c6a68cd23d6a2c2a53a43b4e..2b4a52c85458a348826a3f6743cf9714cd6cdf6d 100644 (file)
@@ -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;