]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_msgs: avoid null pointer deref for early errors
authorDaniel Stenberg <daniel@haxx.se>
Tue, 17 Mar 2026 23:00:52 +0000 (00:00 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 18 Mar 2026 09:40:19 +0000 (10:40 +0100)
When errorf()/warnf() is used early on, before the global pointer is
setup, curl would previosly deref the null pointer.

Follow-up to 3b40128b0f11a3

Found by Codex Security

Closes #20967

src/tool_msgs.c

index 9bc8ca18f12f92c64fca976a1bb4112d01b178b3..2e1245503f6be8bfb5edccda5cf68997b8866955 100644 (file)
@@ -78,7 +78,7 @@ static void voutf(const char *prefix, const char *fmt, va_list ap)
  */
 void notef(const char *fmt, ...)
 {
-  if(global->tracetype) {
+  if(global && global->tracetype) {
     va_list ap;
     va_start(ap, fmt);
     voutf(NOTE_PREFIX, fmt, ap);
@@ -92,7 +92,7 @@ void notef(const char *fmt, ...)
  */
 void warnf(const char *fmt, ...)
 {
-  if(!global->silent) {
+  if(!global || !global->silent) {
     va_list ap;
     va_start(ap, fmt);
     voutf(WARN_PREFIX, fmt, ap);
@@ -128,7 +128,7 @@ void helpf(const char *fmt, ...)
  */
 void errorf(const char *fmt, ...)
 {
-  if(!global->silent || global->showerror) {
+  if(!global || !global->silent || global->showerror) {
     va_list ap;
     va_start(ap, fmt);
     voutf(ERROR_PREFIX, fmt, ap);