Skip to contentSkip to conversation

fsync02: fix error of overflow from MUL

PATCH In review Peng Haitao 2 participants 3 messages Jan 19, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsync02: fix error of overflow from MUL

Hi Garrett,

If the third argument is SEEK_SET of function fsync(), offset can not be negative. But when overflow from MUL, the offset is negative.

---
 testcases/kernel/syscalls/fsync/fsync02.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/fsync/fsync02.c +2 -2
index 213eac3..64bb012 100644
@@ -102,7 +102,7 @@ int main(int ac, char **av)
 		}
 
 		for (i = 1; i <= data_blocks; i++) {
-			offset = (i * BLOCKSIZE * max_block) / data_blocks - BUFSIZ;
+			offset = (BLOCKSIZE * max_block) / data_blocks * i - BUFSIZ;
 			if ((offsetret = lseek(fd, offset, SEEK_SET)) != offset)
 				tst_brkm(TBROK|TERRNO, cleanup, "lseek failed: %ld, %ld", offsetret, offset);
 			if ((ret = write(fd, pbuf, BUFSIZ)) != BUFSIZ)
@@ -197,4 +197,4 @@ void cleanup()
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}
Signature · 17 lines
1.7.3.1

-- 
Best Regards,
Peng Haitao


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw
Quoted 34 lines · Peng Haitao

Hi Garrett,

If the third argument is SEEK_SET of function fsync(), offset can not be negative. But when overflow from MUL, the offset is negative.

---
 testcases/kernel/syscalls/fsync/fsync02.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/fsync/fsync02.c +2 -3
index 213eac3..64bb012 100644
@@ -102,7 +102,7 @@ int main(int ac, char **av)
                }
 
                for (i = 1; i <= data_blocks; i++) {
-                       offset = (i * BLOCKSIZE * max_block) / data_blocks - BUFSIZ;
+                       offset = (BLOCKSIZE * max_block) / data_blocks * i - BUFSIZ;
                        if ((offsetret = lseek(fd, offset, SEEK_SET)) != offset)
                                tst_brkm(TBROK|TERRNO, cleanup, "lseek failed: %ld, %ld", offsetret, offset);
                        if ((ret = write(fd, pbuf, BUFSIZ)) != BUFSIZ)
@@ -197,4 +197,4 @@ void cleanup()
 
        tst_rmdir();
 
-}
\ No newline at end of file
+}
--

1.7.3.1

Quoted 5 lines

--
Best Regards,
Peng Haitao

How about the following item?
Please try the attached patch over the following -- it's just
there for review.
Thanks,
-Garrett

$ git diff testcases/kernel/syscalls/fsync/fsync02.c
(quoted diff) +0 -0

b/testcases/kernel/syscalls/fsync/fsync02.c
index 213eac3..6227a84 100644

testcases/kernel/syscalls/fsync/fsync02.c +0 -1
@@ -102,7 +102,8 @@ int main(int ac, char **av)
                }
 
                for (i = 1; i <= data_blocks; i++) {
-                       offset = (i * BLOCKSIZE * max_block) /

data_blocks - BUFSIZ;
+ offset = i * ((BLOCKSIZE * max_block) / data_blocks);
+ offset -= BUFSIZ;
if ((offsetret = lseek(fd, offset, SEEK_SET)) != offset)
tst_brkm(TBROK|TERRNO, cleanup, "lseek

failed: %ld, %ld", offsetret, offset);
                        if ((ret = write(fd, pbuf, BUFSIZ)) != BUFSIZ)

@@ -197,4 +198,4 @@ void cleanup()

        tst_rmdir();

-}
\ No newline at end of file
+}

From 1a1478a4162cdf2966077101911987fd22300bde Mon Sep 17 00:00:00 2001
From: Garrett Cooper <[email protected]>
Date: Wed, 19 Jan 2011 00:42:31 -0800
Subject: [PATCH] Sort multipliers to avoid accidental overflow.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.7.3.5"

This is a multi-part message in MIME format. --------------1.7.3.5
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit

---
 testcases/kernel/syscalls/fsync/fsync02.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

--------------1.7.3.5
Content-Type: text/x-patch; name="0001-Sort-multipliers-to-avoid-accidental-overflow.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-Sort-multipliers-to-avoid-accidental-overflow.patch"

testcases/kernel/syscalls/fsync/fsync02.c +3 -2
index 213eac3..6227a84 100644
@@ -102,7 +102,8 @@ int main(int ac, char **av)
 		}
 
 		for (i = 1; i <= data_blocks; i++) {
-			offset = (i * BLOCKSIZE * max_block) / data_blocks - BUFSIZ;
+			offset = i * ((BLOCKSIZE * max_block) / data_blocks);
+			offset -= BUFSIZ;
 			if ((offsetret = lseek(fd, offset, SEEK_SET)) != offset)
 				tst_brkm(TBROK|TERRNO, cleanup, "lseek failed: %ld, %ld", offsetret, offset);
 			if ((ret = write(fd, pbuf, BUFSIZ)) != BUFSIZ)
@@ -197,4 +198,4 @@ void cleanup()
 
 	tst_rmdir();
 
-}
\ No newline at end of file
+}

--------------1.7.3.5--

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw

Hi Garrett,

Garrett Cooper said the following on 2011-1-19 16:47:

Quoted 4 lines

How about the following item?
Please try the attached patch over the following -- it's just
there for review.

The patch is OK, thanks:)

Signature · 2 lines
Best Regards,
Peng Haitao
Quoted 22 lines

Thanks,
-Garrett

$ git diff testcases/kernel/syscalls/fsync/fsync02.c
testcases/kernel/syscalls/fsync/fsync02.c +2 -1
index 213eac3..6227a84 100644
@@ -102,7 +102,8 @@ int main(int ac, char **av)
                }
 
                for (i = 1; i <= data_blocks; i++) {
-                       offset = (i * BLOCKSIZE * max_block) /
 data_blocks - BUFSIZ;
+                       offset = i * ((BLOCKSIZE * max_block) / data_blocks);
+                       offset -= BUFSIZ;
                        if ((offsetret = lseek(fd, offset, SEEK_SET)) != offset)
                                tst_brkm(TBROK|TERRNO, cleanup, "lseek
failed: %ld, %ld", offsetret, offset);
                        if ((ret = write(fd, pbuf, BUFSIZ)) != BUFSIZ)

testcases/kernel/syscalls/fsync/fsync02.c void cleanup() · line 201

Quoted 6 lines
testcases/kernel/syscalls/fsync/fsync02.c +1 -1
@@ -197,4 +198,4 @@ void cleanup()
 
        tst_rmdir();
 
-}
\ No newline at end of file
+}

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand malware threats, the impact they can have on your business, and how you can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list