]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
logger: workaround woefully small BUFSIZ in MUSL
authorPhilip Prindeville <philipp@redfish-solutions.com>
Tue, 22 Feb 2022 01:05:49 +0000 (18:05 -0700)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Wed, 23 Mar 2022 21:16:19 +0000 (16:16 -0500)
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@redfish-solutions.com>
Change-Id: Iaa49fbbab029c64ae3d95e4b18270e0442cce170

main/logger.c

index e9f8f9661941c29d714b66697b35d78dd7d275bf..d742b49975a4ca46de88fcd24ae82506f36367b0 100644 (file)
@@ -97,6 +97,11 @@ static int logger_queue_limit = 1000;
 static int logger_messages_discarded;
 static unsigned int high_water_alert;
 
+/* On some platforms, like those with MUSL as the runtime, BUFSIZ is
+ * unreasonably small (1024). Use a larger value in those environments.
+ */
+#define LOGMSG_SIZE            MAX(BUFSIZ, 8192)
+
 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 +1670,7 @@ static struct sigaction handle_SIGXFSZ = {
 static void logger_print_normal(struct logmsg *logmsg)
 {
        struct logchannel *chan = NULL;
-       char buf[BUFSIZ];
+       char buf[LOGMSG_SIZE];
        int level = 0;
 
        AST_RWLIST_RDLOCK(&logchannels);
@@ -1698,13 +1703,13 @@ static void logger_print_normal(struct logmsg *logmsg)
 
                                        /* 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 +1721,7 @@ static void logger_print_normal(struct logmsg *logmsg)
                                                continue;
                                        }
 
-                                       if (chan->formatter.format_log(chan, logmsg, buf, BUFSIZ)) {
+                                       if (chan->formatter.format_log(chan, logmsg, buf, sizeof(buf))) {
                                                continue;
                                        }
 
@@ -1780,7 +1785,7 @@ static struct logmsg * __attribute__((format(printf, 7, 0))) format_log_message_
        }
 
        /* Build string */
-       res = ast_str_set_va(&buf, BUFSIZ, fmt, ap);
+       res = ast_str_set_va(&buf, LOGMSG_SIZE, fmt, ap);
 
        /* If the build failed, then abort and free this structure */
        if (res == AST_DYNSTR_BUILD_FAILED) {