[Asterisk-code-review] logger: workaround woefully small BUFSIZ in MUSL (asterisk[master])

Philip Prindeville asteriskteam at digium.com
Mon Feb 21 19:48:28 CST 2022


Philip Prindeville has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18069 )


Change subject: logger: workaround woefully small BUFSIZ in MUSL
......................................................................

logger: workaround woefully small BUFSIZ in MUSL

MUSL defines BUFSIZ as 1024 which is not reasonable for log messages.

More broadly, BUFSIZ is the amount of buffering stdio.h does, which
is arbitrary and largely orthogonal to what logging should accept
as the maximum message size.

ASTERISK-29928

Signed-off-by: Philip Prindeville <philipp at redfish-solutions.com>
Change-Id: Iaa49fbbab029c64ae3d95e4b18270e0442cce170
---
M main/logger.c
1 file changed, 11 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/18069/1

diff --git a/main/logger.c b/main/logger.c
index e9f8f96..67fcd01 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -97,6 +97,12 @@
 static int logger_messages_discarded;
 static unsigned int high_water_alert;
 
+#if BUFSIZ!=1024
+static const unsigned logger_bufsiz = BUFSIZ;
+#else
+static const unsigned logger_bufsiz = 8192;
+#endif
+
 static enum rotatestrategy {
 	NONE = 0,                /* Do not rotate log files at all, instead rely on external mechanisms */
 	SEQUENTIAL = 1 << 0,     /* Original method - create a new file, in order */
@@ -1665,7 +1671,7 @@
 static void logger_print_normal(struct logmsg *logmsg)
 {
 	struct logchannel *chan = NULL;
-	char buf[BUFSIZ];
+	char buf[logger_bufsiz];
 	int level = 0;
 
 	AST_RWLIST_RDLOCK(&logchannels);
@@ -1698,13 +1704,13 @@
 
 					/* Don't use LOG_MAKEPRI because it's broken in glibc<2.17 */
 					syslog_level = chan->facility | syslog_level; /* LOG_MAKEPRI(chan->facility, syslog_level); */
-					if (!chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
+					if (!chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
 						syslog(syslog_level, "%s", buf);
 					}
 				}
 				break;
 			case LOGTYPE_CONSOLE:
-				if (!chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
+				if (!chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
 					ast_console_puts_mutable_full(buf, logmsg->level, logmsg->sublevel);
 				}
 				break;
@@ -1716,7 +1722,7 @@
 						continue;
 					}
 
-					if (chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
+					if (chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
 						continue;
 					}
 
@@ -1780,7 +1786,7 @@
 	}
 
 	/* Build string */
-	res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
+	res = ast_str_set_va(&buf, logger_bufsiz, fmt, ap);
 
 	/* If the build failed, then abort and free this structure */
 	if (res == AST_DYNSTR_BUILD_FAILED) {

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18069
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Iaa49fbbab029c64ae3d95e4b18270e0442cce170
Gerrit-Change-Number: 18069
Gerrit-PatchSet: 1
Gerrit-Owner: Philip Prindeville <philipp at redfish-solutions.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220221/6a216d62/attachment.html>


More information about the asterisk-code-review mailing list