[PATCH] xkb: Fix NULL pointer dereference in XkbAllocSrvLedInfo

Dirk Wallenstein halsmit at t-online.de
Sat Jun 5 02:25:27 PDT 2010


Put the XkbSrvLedInfoRec allocation in front of the subsequent
branching, and ensure a non-NULL pointer to the new record in a third
branch that was missing that allocation.

Signed-off-by: Dirk Wallenstein <halsmit at t-online.de>
---
This is one item in the recent parfait results.

 xkb/xkbLEDs.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/xkb/xkbLEDs.c b/xkb/xkbLEDs.c
index 6097f85..3a9d307 100644
--- a/xkb/xkbLEDs.c
+++ b/xkb/xkbLEDs.c
@@ -521,12 +521,12 @@ XkbSrvLedInfoPtr	sli;
 Bool			checkAccel;
 Bool			checkNames;
 
-    sli= NULL;
+    sli= calloc(1, sizeof(XkbSrvLedInfoRec));
+    if (sli==NULL)
+        return NULL; /* ALLOCATION ERROR */
     checkAccel= checkNames= FALSE;
     if ((kf!=NULL)&&(kf->xkb_sli==NULL)) {
-	kf->xkb_sli= sli= calloc(1, sizeof(XkbSrvLedInfoRec));
-	if (sli==NULL)
-	    return NULL; /* ALLOCATION ERROR */
+	kf->xkb_sli= sli;
 	if (dev->key && dev->key->xkbInfo)
 	     sli->flags= XkbSLI_HasOwnState;
 	else sli->flags= 0;	
@@ -567,9 +567,7 @@ Bool			checkNames;
 	}
     }
     else if ((lf!=NULL)&&(lf->xkb_sli==NULL)) {
-	lf->xkb_sli= sli= calloc(1, sizeof(XkbSrvLedInfoRec));
-	if (sli==NULL)
-	    return NULL; /* ALLOCATION ERROR */
+	lf->xkb_sli= sli;
 	if (dev->key && dev->key->xkbInfo)
 	     sli->flags= XkbSLI_HasOwnState;
 	else sli->flags= 0;	
-- 
1.7.1



More information about the xorg-devel mailing list