Bug 97157 - rpm assumes strcmp returns specific values
rpm assumes strcmp returns specific values
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: rpm (Show other bugs)
7.2
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jeff Johnson
Mike McLean
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-06-10 19:51 EDT by Need Real Name
Modified: 2007-04-18 12:54 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-04-07 20:24:57 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2003-06-10 19:51:15 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030313

Description of problem:
rpmvercmp assumes that strcmp will return -1,0,1 but according to the
documentation it can be any negative, zero, or positive value.

Line 86 of rpmvercmp.c breaks on glibc-2.2.4-31/32 because strcmp  returns a -2
value. (it works on glibc-2.2.4-13).

Attached patch simply checks for this.



Version-Release number of selected component (if applicable):
4.0.4 - 4.0.5

How reproducible:
Always

Steps to Reproduce:
1. use rpmvercmp
2. it will return a bogus value (253 = 255-2)
3.
    

Additional info:

diff -ru rpm-4.0.5/lib/rpmvercmp.c rpm-4.0.5.fixed/lib/rpmvercmp.c
--- rpm-4.0.5/lib/rpmvercmp.c   Wed Jan 15 12:38:40 2003
+++ rpm-4.0.5.fixed/lib/rpmvercmp.c     Tue Jun 10 19:26:42 2003
@@ -84,7 +84,11 @@
        /* if they are equal because there might be more segments to */
        /* compare */
        rc = strcmp(one, two);
-       if (rc) return rc;
+       if (rc > 0)
+               return 1;
+       else if (rc < 0)
+               return -1;
+
  
        /* restore character that was replaced by null above */
        *str1 = oldch1;
Comment 1 Need Real Name 2003-06-26 15:35:35 EDT
I haven't heard a peep on this bug, so I'am putting a trivial one liner version
of my previous fix in order to generate a new bugzilla email and possibly get a
response...;-)

return rc > 0 ? 1 : -1;
Comment 2 Need Real Name 2003-06-26 15:37:21 EDT
Actually, it should be:

if (rc)
   return rc > 0 ? 1 : -1;
Comment 3 Jeff Johnson 2004-04-07 20:24:57 EDT
Fixed in rpm-4.3.1, probably earlier too.

Note You need to log in before you can comment on or make changes to this bug.