Index | Thread | Search

From:
Christian Ludwig <christian_ludwig@genua.de>
Subject:
dt: Fix potential NULL pointer dereference
To:
<tech@openbsd.org>
Date:
Thu, 29 Feb 2024 15:55:32 +0100

Download raw body.

Thread
  • Christian Ludwig:

    dt: Fix potential NULL pointer dereference

When initializing the profiling probes, check if we sucessfully
allocated the probe, before registering it. This avoids a NULL pointer
dereference when probe allocation failed.

---
 sys/dev/dt/dt_prov_profile.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/dev/dt/dt_prov_profile.c b/sys/dev/dt/dt_prov_profile.c
index 1388770fb39..6d745a57db3 100644
--- a/sys/dev/dt/dt_prov_profile.c
+++ b/sys/dev/dt/dt_prov_profile.c
@@ -53,13 +53,13 @@ int
 dt_prov_profile_init(void)
 {
 	dtpp_profile = dt_dev_alloc_probe("hz", "97", &dt_prov_profile);
-	dt_dev_register_probe(dtpp_profile);
 	if (dtpp_profile == NULL)
 		return 0;
+	dt_dev_register_probe(dtpp_profile);
 	dtpp_interval = dt_dev_alloc_probe("hz", "1", &dt_prov_interval);
-	dt_dev_register_probe(dtpp_interval);
 	if (dtpp_interval == NULL)
 		return 1;
+	dt_dev_register_probe(dtpp_interval);
 	return 2;
 }
 
-- 
2.34.1