[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Proposed Patch for zdump seg fault.
From: |
Sachin Sant |
Subject: |
Proposed Patch for zdump seg fault. |
Date: |
Tue, 30 Sep 2003 11:23:46 +0530 |
I came across a problem with zdump utility on a 64 bit systems. When one
uses the
command " zdump -v GMT " , segmentation fault occurs.
Since on a 64 bit system long is 8 bytes a call to __offtime( ) use to
fail
because of integer overflow [ int being 4 bytes ].
This is a proposed patch to fix the problem. Let me know if its ok
Thanks
-Sachin
-------------------------------------------------------------------------------
--- zdump.c 2003-09-23 20:32:41.000000000 +0530
+++ zdump.c.new 2003-09-30 16:20:34.000000000 +0530
@@ -134,6 +134,18 @@ static size_t longest;
static char * progname;
static void show P((char * zone, time_t t, int v));
+/*
+ * On a 64 bit system zdump use to code dump when given the following
+ * command " zdump -v GMT ".
+ * The reason being __offtime( ) function call use to fail because
+ * of overflow of integer value.
+ * A check on hibit is made so that it does not cross the minimum
+ * and maximum value a integer can hold. The below two defines are
+ * used to check the boundary conditions.
+ */
+#define CHKVALUE (1 << ((8 * sizeof(int)) - 1)) /* Minimum int value */
+#define CHKVALUE2 2147483647 /* Maximum int value
*/
+
int
main(argc, argv)
int argc;
@@ -224,6 +236,11 @@ _("%s: usage is %s [ -v ] [ -c cutoff ]
/*
** Get lowest value of t.
*/
+ /*
+ ** Check if hibit cross the minimum int value.
+ */
+ if (hibit < CHKVALUE)
+ hibit = CHKVALUE;
t = hibit;
if (t > 0) /* time_t is unsigned */
t = 0;
@@ -236,6 +253,14 @@ _("%s: usage is %s [ -v ] [ -c cutoff ]
if (cutoff != NULL && t >= cuttime)
break;
newt = t + SECSPERHOUR * 12;
+ /*
+ * A check was added so that newt would not
+ * exceed maximum value integer can hold.
+ * If it exceeds the value convert it to
+ * proper negative value.
+ */
+ if (newt >= CHKVALUE2)
+ newt = CHKVALUE2 - newt;
if (cutoff != NULL && newt >= cuttime)
break;
if (newt <= t)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Proposed Patch for zdump seg fault.,
Sachin Sant <=