From: Sean Bright Date: Wed, 19 Jan 2011 18:37:09 +0000 (+0000) Subject: Properly handle partial reads from fgets() when handling AGIs. X-Git-Tag: 1.6.2.18-rc1~68 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa527d8ab2929c0eeb8744fdc880568d7e6e7a37;p=thirdparty%2Fasterisk.git Properly handle partial reads from fgets() when handling AGIs. When fgets() failed with EAGAIN, we were continually decrementing the available space left in our buffer, resulting in botched command handling. (closes issue #16032) Reported by: notahat Patches: agi_buffer_patch2.diff uploaded by fnordian (license 110) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.2@302548 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/res/res_agi.c b/res/res_agi.c index 2fbb837b44..c3548906c3 100644 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -2920,7 +2920,7 @@ static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi retry = AGI_NANDFS_RETRY; buf[0] = '\0'; - while (buflen < (len - 1)) { + while (len > 1) { res = fgets(buf + buflen, len, readf); if (feof(readf)) break; @@ -2931,7 +2931,7 @@ static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi buflen = strlen(buf); if (buflen && buf[buflen - 1] == '\n') break; - len -= buflen; + len = sizeof(buf) - buflen; if (agidebug) ast_verbose( "AGI Rx << temp buffer %s - errno %s\n", buf, strerror(errno)); }