[PATCH libxkbfile 02/12] Fix NULL pointer dereference

Pauli Nieminen ext-pauli.nieminen at nokia.com
Wed Jul 21 05:02:46 PDT 2010


xkb can be checked once in begin for NULL when entering XkbWriteXKMFile
where it is derefenced first time.

Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
---
 src/xkmout.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/xkmout.c b/src/xkmout.c
index 403e488..1c0a0a4 100644
--- a/src/xkmout.c
+++ b/src/xkmout.c
@@ -140,7 +140,7 @@ register unsigned	i,bit;
 
     xkb= result->xkb;
     dpy= xkb->dpy;
-    if ((!xkb)||(!xkb->names)||(!xkb->server)) {
+    if ((!xkb->names)||(!xkb->server)) {
 	_XkbLibError(_XkbErrMissingVMods,"SizeXKMVirtualMods",0);
 	return 0;
     }
@@ -209,7 +209,7 @@ Display *	dpy;
 
     xkb= result->xkb;
     dpy= xkb->dpy;
-    if ((!xkb)||(!xkb->names)||(!xkb->names->keys)) {
+    if ((!xkb->names)||(!xkb->names->keys)) {
 	_XkbLibError(_XkbErrMissingNames,"SizeXKMKeycodes",0);
 	return 0;
     }
@@ -273,7 +273,7 @@ char *			name;
 
     xkb= result->xkb;
     dpy= xkb->dpy;
-    if ((!xkb)||(!xkb->map)||(!xkb->map->types)) {
+    if ((!xkb->map)||(!xkb->map->types)) {
 	_XkbLibError(_XkbErrMissingTypes,"SizeXKBKeyTypes",0);
 	return 0;
     }
@@ -385,7 +385,7 @@ Display *	dpy;
 
     xkb= result->xkb;
     dpy= xkb->dpy;
-    if ((!xkb)||(!xkb->compat)||(!xkb->compat->sym_interpret)) {
+    if ((!xkb->compat)||(!xkb->compat->sym_interpret)) {
 	_XkbLibError(_XkbErrMissingCompatMap,"SizeXKMCompatMap",0);
 	return 0;
     }
@@ -481,7 +481,7 @@ char *		name;
 
     xkb= result->xkb;
     dpy= xkb->dpy;
-    if ((!xkb)||(!xkb->map)||((!xkb->map->syms))) {
+    if ((!xkb->map)||((!xkb->map->syms))) {
 	_XkbLibError(_XkbErrMissingSymbols,"SizeXKMSymbols",0);
 	return 0;
     }
@@ -650,7 +650,7 @@ register unsigned	i,nLEDs;
 
     xkb= result->xkb;
     dpy= xkb->dpy;
-    if ((xkb==NULL)||(xkb->indicators==NULL)) {
+    if (xkb->indicators==NULL) {
 /*	_XkbLibError(_XkbErrMissingIndicators,"SizeXKMIndicators",0);*/
 	return 0;
     }
@@ -795,7 +795,7 @@ unsigned	size;
 
     xkb= result->xkb;
     dpy= xkb->dpy;
-    if ((!xkb)||(!xkb->geom))
+    if (!xkb->geom)
 	return 0;
     geom= xkb->geom;
     size= xkmSizeCountedAtomString(dpy,geom->name);
@@ -1016,7 +1016,7 @@ unsigned	tmp,size= 0;
 
     xkb= result->xkb;
     dpy= xkb->dpy;
-    if ((!xkb)||(!xkb->geom))
+    if (!xkb->geom)
 	return 0;
     geom= xkb->geom;
     wire.width_mm= geom->width_mm;
@@ -1321,6 +1321,12 @@ int			(*getTOC)(
 	xkmSectionInfo */* toc_rtrn */
 );
 
+    if (!result->xkb) {
+	_XkbLibError(_XkbErrBadValue,"XkbWriteXKMFile",0);
+	return False;
+    }
+
+
     switch (result->type) {
 	case XkmKeyNamesIndex:
 	    getTOC= GetXKMKeyNamesTOC;
-- 
1.6.3.3



More information about the xorg-devel mailing list