Skip to contentSkip to conversation

xfstests: fix modulo-by-zero error in fsx

PATCH In review Dave Chinner 3 participants 5 messages Jul 19, 2011 – Jul 24, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfstests: fix modulo-by-zero error in fsx

From: Dave Chinner <[email protected]>

The recent fsx fixes has a logic error in the offset trimming code. If a read is done when the file size is zero, then the logic error causes a offset % 0 opertaion to occur. This causes fsx to get a SIGFPE and die.

This was not discovered during my testing because I was using a random seed that didn't trip this condition. Changing the seed to that which test 091 uses (the default of 1) causes such an operation to occur....

---
 ltp/fsx.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
ltp/fsx.c +8 -8
index 771bcdc..d53c498 100644
@@ -987,14 +987,14 @@ docloseopen(void)
 	}
 }
 
-#define TRIM_OFF_LEN(off, len, size, zero_offset)	\
-do {					\
-	if (!zero_offset || file_size)	\
-		offset %= size;		\
-	else				\
-		offset = 0;		\
-	if (offset + len > size)	\
-		len = size - offset;	\
+#define TRIM_OFF_LEN(off, len, size, allow_zero_file_size)	\
+do {						\
+	if (allow_zero_file_size || file_size)	\
+		offset %= size;			\
+	else					\
+		offset = 0;			\
+	if (offset + len > size)		\
+		len = size - offset;		\
 } while (0)
 
 void
Signature · 6 lines
1.7.5.1

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The recent fsx fixes has a logic error in the offset trimming code. If a read is done when the file size is zero, then the logic error causes a offset % 0 opertaion to occur. This causes fsx to get a SIGFPE and die.

This was not discovered during my testing because I was using a random seed that didn't trip this condition. Changing the seed to that which test 091 uses (the default of 1) causes such an operation to occur....

Looks good,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
In reply to Dave Chinner
Quoted 7 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The recent fsx fixes has a logic error in the offset trimming code. If a read is done when the file size is zero, then the logic error causes a offset % 0 opertaion to occur. This causes fsx to get a SIGFPE and die.

Quoted 6 lines

This was not discovered during my testing because I was using a random seed that didn't trip this condition. Changing the seed to that which test 091 uses (the default of 1) causes such an operation to occur....

I realize you already committed this, but I'm finally getting around to reviewing it.

I started composing this message, explaining how you should have done something differently. But at this point it'll be more constructive to just send a patch against what you have already committed. So that will be coming shortly...

-Alex

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 15 lines · Alex Elder
Quoted 7 lines · Dave Chinner

From: Dave Chinner <[email protected]>

The recent fsx fixes has a logic error in the offset trimming code. If a read is done when the file size is zero, then the logic error causes a offset % 0 opertaion to occur. This causes fsx to get a SIGFPE and die.

Quoted 6 lines

This was not discovered during my testing because I was using a random seed that didn't trip this condition. Changing the seed to that which test 091 uses (the default of 1) causes such an operation to occur....

Quoted 8 lines

I realize you already committed this, but I'm finally getting around to reviewing it.

I started composing this message, explaining how you should have done something differently. But at this point it'll be more constructive to just send a patch against what you have already committed. So that will be coming shortly...

Yeah, better to have something working that perfect. Feel free to make it better ;)

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs