bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

findutils-4.1: locate misparses shorts in database


From: Ken Lalonde
Subject: findutils-4.1: locate misparses shorts in database
Date: Thu, 9 Jan 2003 14:54:57 -0500 (EST)

Further to my previous bug report today:
locate reads a series of byte count differences for the next
pathname in the database.  In the case when the difference
is too large to fit in one byte, it is encoded in two
bytes, in network order.

The problem is that the signed two byte value is incorrectly
decoded -- the sign bit is lost, and the result is a large
positive number.  This bug led to the buffer
allocation problem I described in my previous message today.

As before, I can send a tar archive containing the tree that 
demonstrates the bug, if you need it.

The fix is simple; see below.

In passing I'd like to say that fixing bugs in a utility that
hasn't changed in nearly 10 years is a gas.


*** /tmp/k/o/findutils-4.1/locate/locate.c      Mon Sep 26 18:06:14 1994
--- ./locate.c  Thu Jan  9 14:43:48 2003
***************
*** 101,109 ****
       FILE *fp;
  {
    register short x;
  
!   x = fgetc (fp);
!   return (x << 8) | (fgetc (fp) & 0xff);
  }
  
  /* Return a pointer to the last character in a static copy of the last
--- 101,112 ----
       FILE *fp;
  {
    register short x;
+   int c1, c2;
  
!   c1 = fgetc(fp);
!   c2 = fgetc(fp);
!   x = (c1 << 8) | (c2 & 0xff);
!   return (int)x;
  }
  
  /* Return a pointer to the last character in a static copy of the last




reply via email to

[Prev in Thread] Current Thread [Next in Thread]