[PATCH libxkbfile 12/12] Add NULL check for strtok return value

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


strtok may retyurn NULL if parsed file is formated incorrectly. To
prevent possible NULL pointer dereference check for strtok return value.

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

diff --git a/src/maprules.c b/src/maprules.c
index e7ba8c4..b2476ac 100644
--- a/src/maprules.c
+++ b/src/maprules.c
@@ -1116,7 +1116,11 @@ int			len,headingtype,extra_ndx = 0;
     for ( ; GetInputLine(file,&line,False); line.num_line= 0) {
 	if (line.line[0]=='!') {
 	    tok = strtok(&(line.line[1]), " \t");
-	    if (strcmp(tok,"model") == 0)
+	    if (tok == NULL) {
+		headingtype = HEAD_NONE;
+		PR_DEBUG("Unable to find space or tab after '!'\n");
+		PR_DEBUG("Illegal header line\n");
+	    } else if (strcmp(tok,"model") == 0)
 		headingtype = HEAD_MODEL;
 	    else if (_XkbStrCaseCmp(tok,"layout") == 0)
 		headingtype = HEAD_LAYOUT;
-- 
1.6.3.3



More information about the xorg-devel mailing list