gnustep / libobjc2

Objective-C runtime library intended for use with Clang.
http://www.gnustep.org/
MIT License
441 stars 119 forks source link

Fix offsets in selector_table #273

Closed hmelder closed 10 months ago

hmelder commented 10 months ago

Seems like the NUL check and offsets are wrong here.

triplef commented 10 months ago

Good finds! Can you comment on what kinds of issues this might have caused at runtime?

hmelder commented 10 months ago

Can you comment on what kinds of issues this might have caused at runtime?

This one should only be relevant if you are using GCC (or an object file compiled using GCC), as it generates "" for `@encode(BOOL)`, while Clang generates "^c" or "^C". When comparing type encodings, we check for both options.

        if ((*t1 == '*') && (*t2 != '*'))
        {
-           if (*t2 == '^' && (((*(t2+1) == 'C') || (*(t2+2) == 'c'))))
+           if (*t2 == '^' && (((*(t2+1) == 'C') || (*(t2+1) == 'c'))))

Here we do not stop if the second string ends, but as the pointer increment is guarded by an additional check (See line 216), we keep comparing the next char from t1 with \0 until t1 is also \0.

-   while (('\0' != *t1) && ('\0' != *t1))
+   while (('\0' != *t1) && ('\0' != *t2))