Skip to contentSkip to conversation

Missing NULL check in __nc_error()

Libtirpc-devel Susant Sahani 1 participant 1 message Nov 20, 2013 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#3 lore raw
In reply to a message not in the archive

Hi Steve,
In the file: getnetconfig.c __nc_error() does not check return
value from malloc() and can pass NULL pointer to thr_setspecific() which can lead to crash. Attached fix.

Thanks,
Susant

Quoted 41 lines · Susant Sahani

Yes was reading out the code. Could be because of out of memory also .

Quoted 14 lines · Chuck Lever

Hi-

Quoted 3 lines · Susant Sahani

Hi,

__nc_error() does not check return value from malloc() can lead to crash .

Curious. Did you see an actual NULL return from malloc(), or did you notice this via code inspection? A NULL return is rare and usually indicates a deeper problem.

Quoted 1 line

trying get familiar with with patch submission

Start here for details on formatting your submission, and legal requirements:

https://www.kernel.org/doc/Documentation/SubmittingPatches

Quoted 10 lines

Send patches to Steve Dickson <[email protected]>, and cc this mailing list.

Thanks.

--
Chuck Lever
chucklever[at]gmail[dot]com

Thanks,
Susant

------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Libtirpc-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/libtirpc-devel

Quoted 1 line

From 72d43756f09599da9d0907c9f62c6a8e1e0cb261 Mon Sep 17 00:00:00 2001

From: Susant Sahani <[email protected]>
Date: Tue, 19 Nov 2013 08:40:00 +0530
Subject: [PATCH] __nc_error() does not check return value from malloc

---
 src/getnetconfig.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/getnetconfig.c +2 -1
index af4a484..2460a6e 100644
@@ -146,7 +146,8 @@ __nc_error()
 			return (&nc_error);
 	}
 	if ((nc_addr = (int *)thr_getspecific(nc_key)) == NULL) {
-		nc_addr = (int *)malloc(sizeof (int));
+		if((nc_addr = (int *)malloc(sizeof (int))) == NULL)
+			return (&nc_error);
 		if (thr_setspecific(nc_key, (void *) nc_addr) != 0) {
 			if (nc_addr)
 				free(nc_addr);
Signature · 1 line
1.8.4.2