[svn-commits] mjordan: trunk r417800 - in /trunk: ./ main/utils.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 3 06:27:31 CDT 2014


Author: mjordan
Date: Thu Jul  3 06:27:25 2014
New Revision: 417800

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=417800
Log:
main/untils: Prevent potential infinite loop in ast_careful_fwrite

A loop in ast_careful_fwrite exists that will continually attempt to write to
a file stream, even in the presence of EAGAIN/EINTR errors. However, if a
connection that uses ast_careful_fwrite closes suddenly, ast_careful_fwrite's
call to fflush may return EAGAIN/EINTER along with EOF. A subsequent call to
fflush will return EOF but not clear errno, resulting in an infinite loop.

This patch clears errno after it is detected and handled the loop, such that
any subsequent call to fflush will not get erroneously stuck.

Review: https://reviewboard.asterisk.org/r/3704

#ASTERISK-23984 #close
Reported by: Steve Davies
patches:
  fflush_loop_fix uploaded by one47 (License 5012)
........

Merged revisions 417797 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 417798 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 417799 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/main/utils.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/utils.c?view=diff&rev=417800&r1=417799&r2=417800
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Thu Jul  3 06:27:25 2014
@@ -1411,11 +1411,18 @@
 		}
 	}
 
+	errno = 0;
 	while (fflush(f)) {
 		if (errno == EAGAIN || errno == EINTR) {
+			/* fflush() does not appear to reset errno if it flushes
+			 * and reaches EOF at the same time. It returns EOF with
+			 * the last seen value of errno, causing a possible loop.
+			 * Also usleep() to reduce CPU eating if it does loop */
+			errno = 0;
+			usleep(1);
 			continue;
 		}
-		if (!feof(f)) {
+		if (errno && !feof(f)) {
 			/* Don't spam the logs if it was just that the connection is closed. */
 			ast_log(LOG_ERROR, "fflush() returned error: %s\n", strerror(errno));
 		}




More information about the svn-commits mailing list