Home page logo
/

bugtraq logo Bugtraq mailing list archives

Re: gcc 4.1 bug miscompiles pointer range checks, may place you at risk
From: Gabor Gombas <gombasg () sztaki hu>
Date: Tue, 18 Apr 2006 11:21:40 +0200

On Mon, Apr 17, 2006 at 10:03:54PM +0200, Felix von Leitner wrote:

static inline int range_ptrinbuf(const void* buf,unsigned long len,const void* ptr) {
  register const char* c=(const char*)buf;      /* no pointer arithmetic on void* */
  return (c && c+len>c && (const char*)ptr-c<len);
}

$ gcc-4.1 -W -Wall t.c
t.c:5: warning: comparison between signed and unsigned

gcc 3 compiles this code correctly.  I tested this on x86 and amd64.
I mention this here because "c+len>c" is the code with which you would
typically check for integer overflows, which is a check that for example
an IP stack would do, or Samba.

AFAIK C99 states that the value of that expression is "undefined". So
IMHO this is an application bug, not a bug in gcc.

Gabor

-- 
     ---------------------------------------------------------
     MTA SZTAKI Computer and Automation Research Institute
                Hungarian Academy of Sciences
     ---------------------------------------------------------


  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]