Skip to content

scanner: don't accept invalid symbols in binary expressions

The rules for binary expressions were entirely oblivious to the type of the operand symbols and assumed they're integer constants.

This is very unfortunate, since it caused all sort of nonsense to end up getting accepted. One such example is the following define from NetworkManager's libnm:

  #define NM_SETTING_PARAM_SECRET (1 << (2 + G_PARAM_USER_SHIFT))

As G_PARAM_USER_SHIFT is unknown, it was parsed as an invalid symbol. The addition didn't care, treated it as:

  #define NM_SETTING_PARAM_SECRET (1 << (2 + 0))

Let's just ensure we get CSYMBOL_TYPE_CONST only when both operands actually have const_int_set. Otherwise just create CSYMBOL_TYPE_INVALID. That will cause the symbol to be dropped on the floor eventually, but that's probably much better than a having an invalid value.

Merge request reports