bug-global
[Top][All Lists]
Advanced

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

Fixed 64bits bug where large long sysconf() values where cast into negat


From: Marc Herbert
Subject: Fixed 64bits bug where large long sysconf() values where cast into negative ints.
Date: Thu, 13 Jan 2011 18:56:10 +0000
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7

Hi,

I found this bug while running "global -u -v" on a 64 bits system.

Without the bug:

 [1/2] deleting tags of mlips/include/foo.h
 [2/2] deleting tags of mlips/include/bar.h
 [1/2] adding tags of mlips/include/foo.h
 [2/2] adding tags of mlips/include/bar.h

When a very large 64 bits value is returned by sysconf, it is cast to
a negative int and the bug is triggered. Then global is just deleting
symbols instead:

 [1/2] deleting tags of mlips/include/foo.h
 [2/2] deleting tags of mlips/include/bar.h


 This cause of this bug was very well hidden because negative values
were changed to zero. I cannot understand why: a limit of zero still
does not work, it just hides this bug.

Regards,

Marc


diff --git a/libutil/xargs.c b/libutil/xargs.c
index 94627dd..a1dba63 100644
--- a/libutil/xargs.c
+++ b/libutil/xargs.c
@@ -38,6 +38,7 @@
 #include "xargs.h"
 
 #if !defined(ARG_MAX) && defined(_SC_ARG_MAX)
+/* FIXME: in theory sysconf() can return -1L for unlimited */
 #define ARG_MAX         sysconf(_SC_ARG_MAX)
 #endif
 
@@ -70,7 +71,7 @@ static XARGS *xargs_open_generic(const char *, int);
 static int
 exec_line_limit(int length)
 {
-       int limit = 0;
+       long limit = 0;
 
 #ifdef ARG_MAX
        /*
@@ -105,7 +106,8 @@ exec_line_limit(int length)
        limit = 2047 - length - 80;
 #endif
        if (limit < 0)
-               limit = 0;
+               die("Negative exec line limit = %ld", limit);
+
        return limit;
 }
 /*






reply via email to

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