Re: [PATCH] Re: [Exim] negative integer options gone in 4.20…

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Michael Haardt
Date:  
À: exim-users
Sujet: Re: [PATCH] Re: [Exim] negative integer options gone in 4.20, causing some grief
> - if (tolower(s[count]) == 'k') { value *= 1024; count++; }
> -  else if (tolower(s[count]) == 'm') { value *= 1024*1024; count++; }
> +  {
> +    int ov = value;
> +    if (tolower(s[count]) == 'k') { value *= 1024; count++; }
> +    else if (tolower(s[count]) == 'm') { value *= 1024*1024; count++; }

>
> -  if (value < 0) log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
> -    "integer \"%s\" is too large (overflow)", s);
> +    if (value < 0 && ov > 0) log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
> +      "integer \"%s\" is too large (overflow)", s);
> +  }


Just thinking about it: Does the assumption of value < 0 indicating
overflow always hold?

I don't know any systems where signed integer overflows cause exceptions,
but I think C allows that to happen, so how about this:

if (tolower(s[count]) == 'k')
  {
  if (ok = (value>0 ? value>INT_MAX/1024 : value <INT_MIN/1024))
    value *= 1024;
  }
  count++;


Not tested, just a thought. In case negative values are not allowed,
things are even easier.

Michael