eolian: fix out-of-bounds indexing on tokens
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Sun, 4 Oct 2015 13:52:36 +0000 (14:52 +0100)
committerDaniel Kolesa <d.kolesa@osg.samsung.com>
Sun, 4 Oct 2015 13:54:21 +0000 (14:54 +0100)
Fixes CID 1324818 @fix

src/lib/eolian/eo_lexer.c

index bd78958..d14c70f 100644 (file)
@@ -1148,8 +1148,9 @@ eo_lexer_token_to_str(int token, char *buf)
      {
         const char *v;
         size_t idx = token - START_CUSTOM;
-        if (idx >= sizeof(tokens))
-          v = keywords[idx - sizeof(tokens)];
+        size_t tsz = sizeof(tokens) / sizeof(tokens[0]);
+        if (idx >= tsz)
+          v = keywords[idx - tsz];
         else
           v = tokens[idx];
         memcpy(buf, v, strlen(v) + 1);