public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] fs: fat: fix fatwrite overflow calculation
@ 2017-08-13 19:16 Reno Farnesi
  2017-08-26 20:45 ` [U-Boot] " Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Reno Farnesi @ 2017-08-13 19:16 UTC (permalink / raw)
  To: u-boot

The overflow calculation was incorrect. Adding the start block of the
partition is not needed because the sectors are already relative to the
beginning of the partition. If you attempted to write a file smaller
than cur_part_info.start blocks on a full partition the old calculation
fails to catch the overflow. This would cause an infinite loop in the
determine_fatent function.

Old, incorrect calculation:

ending sector of new file = start sector + file size (in sectors)
last sector = partition start + total sectors on the partition

Adding the partition start block number is not needed because sectors
are already relative to the start of the partition.

New calculation:

ending sector of new file = start sector + file size (in sectors)
last sector = total sectors on the partition

Signed-off-by: Reno Farnesi <nfarnesi4@gmail.com>
---

 fs/fat/fat_write.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index f6f06289f4..4ca024c208 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -762,7 +762,7 @@ static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size)
 	if (offset != 0)
 		sect_num++;
 
-	if (startsect + sect_num > cur_part_info.start + total_sector)
+	if (startsect + sect_num > total_sector)
 		return -1;
 	return 0;
 }
-- 
2.13.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] fs: fat: fix fatwrite overflow calculation
  2017-08-13 19:16 [U-Boot] [PATCH] fs: fat: fix fatwrite overflow calculation Reno Farnesi
@ 2017-08-26 20:45 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2017-08-26 20:45 UTC (permalink / raw)
  To: u-boot

On Sun, Aug 13, 2017 at 03:16:17PM -0400, Reno Farnesi wrote:

> The overflow calculation was incorrect. Adding the start block of the
> partition is not needed because the sectors are already relative to the
> beginning of the partition. If you attempted to write a file smaller
> than cur_part_info.start blocks on a full partition the old calculation
> fails to catch the overflow. This would cause an infinite loop in the
> determine_fatent function.
> 
> Old, incorrect calculation:
> 
> ending sector of new file = start sector + file size (in sectors)
> last sector = partition start + total sectors on the partition
> 
> Adding the partition start block number is not needed because sectors
> are already relative to the start of the partition.
> 
> New calculation:
> 
> ending sector of new file = start sector + file size (in sectors)
> last sector = total sectors on the partition
> 
> Signed-off-by: Reno Farnesi <nfarnesi4@gmail.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170826/2d3b263d/attachment.sig>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-26 20:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-13 19:16 [U-Boot] [PATCH] fs: fat: fix fatwrite overflow calculation Reno Farnesi
2017-08-26 20:45 ` [U-Boot] " Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox