icculus / mojoshader

Use Direct3D shaders with other 3D rendering APIs.
https://icculus.org/mojoshader/
zlib License
122 stars 36 forks source link

./lemon segfaults on architectures where char is unsigned #49

Closed smcv closed 2 years ago

smcv commented 2 years ago

According to https://bugs.debian.org/976553, mojoshader's build fails on architectures where char is unsigned, such as arm64: the ./lemon parser generator segfaults during the build. I think this is because hash can become negative, causing out-of-bounds access to memory before types[0].

Debian developer Adrian Bunk suggested this one-line patch, which I'll turn into a pull request. (FTBFS is a Debian shorthand for "fails to build from source", because it's such a common class of bug for distributions to have to deal with.)

Description: Fix FTBFS on architectures where char is unsigned
Author: Adrian Bunk <bunk@debian.org>
Bug-Debian: https://bugs.debian.org/976553

--- mojoshader-0.0~hg1314+dfsg.orig/misc/lemon.c
+++ mojoshader-0.0~hg1314+dfsg/misc/lemon.c
@@ -3466,7 +3466,7 @@ void print_stack_union(
   int maxdtlength;          /* Maximum length of any ".datatype" field. */
   char *stddt;              /* Standardized name for a datatype */
   int i,j;                  /* Loop counters */
-  int hash;                 /* For hashing the name of a type */
+  unsigned int hash;        /* For hashing the name of a type */
   const char *name;         /* Name of the parser */

   /* Allocate and initialize types[] and allocate stddt[] */
icculus commented 2 years ago

This took forever, but I merged the latest Lemon from sqlite. It worked here generally, and it has the unsigned char fix, but let me know if this broke other things.