diff options
author | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2010-03-05 18:08:11 +0100 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2010-03-05 18:08:11 +0100 |
commit | b4e293558266d9ae2f7971c682ac0846972005f8 (patch) | |
tree | ebd4c134c4a6dd0ad50c8d49c50e63767cd83d3f | |
parent | 859d2c1cb12f8752fb416eb275ef8282cff10ea4 (diff) | |
download | pianobar-b4e293558266d9ae2f7971c682ac0846972005f8.tar.gz pianobar-b4e293558266d9ae2f7971c682ac0846972005f8.tar.bz2 pianobar-b4e293558266d9ae2f7971c682ac0846972005f8.zip |
waitress: Abort reading if server closes connection
Caused infinite loops under certain circumstances.
-rw-r--r-- | libwaitress/src/waitress.c | 4 | ||||
-rw-r--r-- | libwaitress/src/waitress.h | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/libwaitress/src/waitress.c b/libwaitress/src/waitress.c index 26ed493..70a1547 100644 --- a/libwaitress/src/waitress.c +++ b/libwaitress/src/waitress.c @@ -394,6 +394,10 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) { nextLine = recvBuf; while (hdrParseMode != HDRM_FINISHED) { READ_RET (recvBuf+bufFilled, sizeof (recvBuf)-1 - bufFilled, &recvSize); + if (recvSize == 0) { + /* connection closed too early */ + CLOSE_RET (WAITRESS_RET_CONNECTION_CLOSED); + } bufFilled += recvSize; memset (recvBuf+bufFilled, 0, sizeof (recvBuf) - bufFilled); thisLine = recvBuf; diff --git a/libwaitress/src/waitress.h b/libwaitress/src/waitress.h index 5c266ae..5fa1874 100644 --- a/libwaitress/src/waitress.h +++ b/libwaitress/src/waitress.h @@ -55,8 +55,9 @@ typedef enum {WAITRESS_RET_ERR = 0, WAITRESS_RET_OK, WAITRESS_RET_STATUS_UNKNOWN WAITRESS_RET_NOTFOUND, WAITRESS_RET_FORBIDDEN, WAITRESS_RET_CONNECT_REFUSED, WAITRESS_RET_SOCK_ERR, WAITRESS_RET_GETADDR_ERR, WAITRESS_RET_CB_ABORT, WAITRESS_RET_HDR_OVERFLOW, - WAITRESS_RET_PARTIAL_FILE, WAITRESS_RET_TIMEOUT, WAITRESS_RET_READ_ERR} - WaitressReturn_t; + WAITRESS_RET_PARTIAL_FILE, WAITRESS_RET_TIMEOUT, WAITRESS_RET_READ_ERR, + WAITRESS_RET_CONNECTION_CLOSED +} WaitressReturn_t; void WaitressInit (WaitressHandle_t *); void WaitressFree (WaitressHandle_t *); |