This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Avoid bogus pointer->int cast


On 07/17/2012 07:45 PM, Eric Blake wrote:
On 07/17/2012 11:26 AM, Ralf Corsepius wrote:
On 07/17/2012 07:21 PM, Ralf Corsepius wrote:
Hi,

The patch below addresses a (minor) bug in readdir.c. It replaces a
(bogus) pointer->int cast with a pointer->intptr_t cast.

Rather than "fixing" the bogus pointer check, why not just nuke that code altogether?

My goal was to make the existing code compilable by removing invalid code, not rewrite it.


+#include <stdint.h>

In other words, no need to drag this in...


#include <dirent.h>

  extern int getdents (int fd, void *dp, int count);
@@ -75,7 +76,7 @@ _DEFUN(readdir, (dirp),
        continue;
      }
      dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc);

and everything between here...


-    if ((int)dp & 03) {	/* bogus pointer check */
+    if ((intptr_t)dp & 03) {	/* bogus pointer check */
  #ifdef HAVE_DD_LOCK
        __lock_release_recursive(dirp->dd_lock);
  #endif
       return NULL;
     }

...and here is just stupid.  POSIX already states that behavior is
undefined if you pass in a bogus pointer; and in a compliant program,
readdir should only ever be called on a valid pointer, making this check
look like nothing more than dead code.  I see no need to bloat the code
with an attempt to gracefully deal with a bogus pointer.

This is a different issue than I was addressing.


Ralf


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]