From fc9ea9eab096c5f8c04c82ccc8d7b8e1372a48dd Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Tue, 24 Jul 2012 00:00:01 +0200 Subject: [PATCH] ftmod_isdn: Handle zero length read correctly. ftmod_misdn currently returns len == 0 if the incoming message, that triggered the read() call, does not contain any data. Users of ftdm_channel_read() need to handle this case, or they may possibly end up in an endless loop. This patch reworks the ftdm_channel_read() handling in ftmod_isdn and prevents it from entering an endless loop. The read error counter is reset on first sucessful read w/ data. Signed-off-by: Stefan Knoblich --- libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c index c3bd175328..4d6c2dcb79 100644 --- a/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c +++ b/libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c @@ -2055,10 +2055,13 @@ static void *ftdm_isdn_run(ftdm_thread_t *me, void *obj) break; default: { - errs = 0; if (flags & FTDM_READ) { len = sizeof(frame); - if (ftdm_channel_read(isdn_data->dchan, frame, &len) == FTDM_SUCCESS) { + if (ftdm_channel_read(isdn_data->dchan, frame, &len) != FTDM_SUCCESS) { + ftdm_log_chan_msg(isdn_data->dchan, FTDM_LOG_ERROR, "Failed to read from D-Channel\n"); + continue; + } + if (len > 0) { #ifdef HAVE_PCAP if (isdn_pcap_capture_both(isdn_data)) { isdn_pcap_write(isdn_data, frame, len, ISDN_PCAP_INCOMING); @@ -2066,6 +2069,9 @@ static void *ftdm_isdn_run(ftdm_thread_t *me, void *obj) #endif Q921QueueHDLCFrame(&isdn_data->q921, frame, (int)len); Q921Rx12(&isdn_data->q921); + + /* Successful read, reset error counter */ + errs = 0; } } else { ftdm_log(FTDM_LOG_DEBUG, "No Read FLAG!\n");