[Openvpn-devel,v1] pool: Fix a potential NULL pointer de-reference in test code

Message ID 20260508153156.13575-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] pool: Fix a potential NULL pointer de-reference in test code |

Commit Message

Gert Doering May 8, 2026, 3:31 p.m. UTC
  From: Frank Lichtenheld <frank@lichtenheld.com>

Identified by cppcheck. Probably has been a long time
since that code has been compiled, though.

Change-Id: I09ebbf6f3555dd68ce8d75bfa844ecac518a0cf2
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1676
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1676
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <gert@greenie.muc.de>
  

Comments

Gert Doering May 13, 2026, 9:15 a.m. UTC | #1
Indeed, cn could be NULL if we're testing that case... not sure that
code is very useful in this form (nobody ever builds -DSOMETHING_TEST
these days) - it should become a unit test whenever we work on pool
handling next time.

This said, if it can be NULL, and we're not on an OS that tolerates
"pass NULL to %s", this breaks in the wrong place, so fixing is good
(not something compiled on 2.7, so only fixing master).

Your patch has been applied to the master branch.

commit b887872524d6fc481c23bfac20c3f5d117547eba
Author: Frank Lichtenheld
Date:   Fri May 8 17:31:51 2026 +0200

     pool: Fix a potential NULL pointer de-reference in test code

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1676
     Message-Id: <20260508153156.13575-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36865.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering
  

Patch

diff --git a/src/openvpn/pool.c b/src/openvpn/pool.c
index 15004c0..ff74e7c 100644
--- a/src/openvpn/pool.c
+++ b/src/openvpn/pool.c
@@ -757,7 +757,7 @@ 
             break;
         }
         msg(M_INFO | M_NOPREFIX, "IFCONFIG_POOL TEST pass 1: l=%s r=%s cn=%s",
-            print_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc), cn);
+            print_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc), cn ? cn : "[NULL]");
         array[i] = h;
     }
 
@@ -793,7 +793,7 @@ 
             break;
         }
         msg(M_INFO | M_NOPREFIX, "IFCONFIG_POOL TEST pass 3: l=%s r=%s cn=%s",
-            print_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc), cn);
+            print_in_addr_t(local, 0, &gc), print_in_addr_t(remote, 0, &gc), cn ? cn : "[NULL]");
         array[i] = h;
     }