]> git.kaiwu.me - nginx.git/commitdiff
Xslt: fix handling of vsnprintf() return value
authorBoris Tonofa <b.tonofa@ideco.ru>
Fri, 20 Jun 2025 15:16:16 +0000 (18:16 +0300)
committerSergey Kandaurov <s.kandaurov@f5.com>
Mon, 8 Jun 2026 10:29:08 +0000 (14:29 +0400)
src/http/modules/ngx_http_xslt_filter_module.c

index 4e6e1b99d243e6b34bae80418b17d55c6e81662c..38bc7c52b4841bf50c693c8c8f7a5094649d606d 100644 (file)
@@ -465,7 +465,7 @@ ngx_http_xslt_sax_error(void *data, const char *msg, ...)
 {
     xmlParserCtxtPtr ctxt = data;
 
-    size_t                       n;
+    int                          n;
     va_list                      args;
     ngx_http_xslt_filter_ctx_t  *ctx;
     u_char                       buf[NGX_MAX_ERROR_STR];
@@ -475,13 +475,23 @@ ngx_http_xslt_sax_error(void *data, const char *msg, ...)
     buf[0] = '\0';
 
     va_start(args, msg);
-    n = (size_t) vsnprintf((char *) buf, NGX_MAX_ERROR_STR, msg, args);
+    n = vsnprintf((char *) buf, NGX_MAX_ERROR_STR, msg, args);
     va_end(args);
 
+    if (n <= 0) {
+        ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, ngx_errno,
+                      "libxml2 error");
+        return;
+    }
+
+    if (n > NGX_MAX_ERROR_STR) {
+        n = NGX_MAX_ERROR_STR;
+    }
+
     while (--n && (buf[n] == CR || buf[n] == LF)) { /* void */ }
 
     ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0,
-                  "libxml2 error: \"%*s\"", n + 1, buf);
+                  "libxml2 error: \"%*s\"", (size_t) (n + 1), buf);
 }