Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-22 Thread via GitHub


Donny9 commented on PR #12188:
URL: https://github.com/apache/nuttx/pull/12188#issuecomment-2068590626

   > > > @Donny9 in rwb_wrflush(): memmove(rwb->wrbuffer + padblocks * 
rwb->blocksize, rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
   > > > when the offest from rwb->wrblockstart to startblock plus 
rwb->wrnblocks is greater than rwb->wralignblocks, it will be causing memory 
overflow since rwb->wrbuffer is allocated rwb.wrmaxblock(rwb.wralignblocks) 
blocks.
   > > > For more detail,we can communicate in wechat:chen_chuang_1030
   > > 
   > > 
   > > @ChenChuangForLinux i got, I will improve a new patch to solve this 
problem instead of expanding the buffer
   > 
   > OK, maybe rwb_writebuffer() is a good starting point
   
   @ChenChuangForLinux  you can try this patch 
https://github.com/apache/nuttx/pull/12202


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-21 Thread via GitHub


ChenChuangForLinux commented on PR #12188:
URL: https://github.com/apache/nuttx/pull/12188#issuecomment-2067965309

   > > @Donny9 in rwb_wrflush(): memmove(rwb->wrbuffer + padblocks * 
rwb->blocksize, rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
   > > when the offest from rwb->wrblockstart to startblock plus rwb->wrnblocks 
is greater than rwb->wralignblocks, it will be causing memory overflow since 
rwb->wrbuffer is allocated rwb.wrmaxblock(rwb.wralignblocks) blocks.
   > > For more detail,we can communicate in wechat:chen_chuang_1030
   > 
   > @ChenChuangForLinux i got, I will improve a new patch to solve this 
problem instead of expanding the buffer
   
   OK, maybe rwb_writebuffer() is a good starting point


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-21 Thread via GitHub


Donny9 commented on PR #12188:
URL: https://github.com/apache/nuttx/pull/12188#issuecomment-2067962532

   > @Donny9 in rwb_wrflush(): memmove(rwb->wrbuffer + padblocks * 
rwb->blocksize, rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
   > 
   > when the offest from rwb->wrblockstart to startblock plus rwb->wrnblocks 
is greater than rwb->wralignblocks, it will be causing memory overflow since 
rwb->wrbuffer is allocated rwb.wrmaxblock(rwb.wralignblocks) blocks.
   > 
   > For more detail,we can communicate in wechat:chen_chuang_1030
   
   @ChenChuangForLinux i got, I will improve a new patch to solve this problem 
instead of expanding the buffer


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-21 Thread via GitHub


ChenChuangForLinux commented on PR #12188:
URL: https://github.com/apache/nuttx/pull/12188#issuecomment-2067942471

   @Donny9 in rwb_wrflush():
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
 rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
   
   when the offest from rwb->wrblockstart to startblock plus rwb->wrnblocks is 
greater than rwb->wralignblocks, it will be causing memory overflow since 
rwb->wrbuffer is allocated rwb.wrmaxblock(rwb.wralignblocks) blocks.
   
   For more detail,we can communicate in wechat:chen_chuang_1030 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-21 Thread via GitHub


Donny9 commented on PR #12188:
URL: https://github.com/apache/nuttx/pull/12188#issuecomment-2067937759

   @ChenChuangForLinux In what specific function will this overflow occur? Why 
can't we write in two parts? First align the first part and flush it, and then 
put the second part into the wrbuffer.
   The writebuffer is already large for nand flsh with 256K eraseblock, double 
it will be 512K


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-20 Thread via GitHub


acassis merged PR #12188:
URL: https://github.com/apache/nuttx/pull/12188


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-20 Thread via GitHub


ChenChuangForLinux opened a new pull request, #12188:
URL: https://github.com/apache/nuttx/pull/12188

   when the offest from rwb->wrblockstart to startblock plus rwb->wrnblocks is 
greater than rwb->wralignblocks, it will be causing memory overflow since 
rwb->wrbuffer is allocated rwb.wrmaxblock(rwb.wralignblocks) blocks.
   
   ## Summary
   
   ## Impact
   
   ## Testing
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-20 Thread via GitHub


ChenChuangForLinux closed pull request #12056: fix: the bug about rwbuffer 
causing mem overflow
URL: https://github.com/apache/nuttx/pull/12056


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-14 Thread via GitHub


xiaoxiang781216 commented on PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#issuecomment-2053981191

   @ChenChuangForLinux please remove the merge patch from pr.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-14 Thread via GitHub


xiaoxiang781216 commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1564585552


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,50 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  uint8_t *tmp = NULL;
+  size_t tmp_blocks = 0;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  if (padblocks + rwb->wrnblocks > rwb->wralignblocks)
+{
+  tmp_blocks = padblocks - rwb->wrnblocks -
+rwb->wralignblocks;
+  tmp = kmm_malloc(tmp_blocks * rwb->blocksize);

Review Comment:
   it isn't good to allocate temp buffer in the hot path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-14 Thread via GitHub


ChenChuangForLinux commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1564556600


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   The latest PR is my final solution based on the original idea.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-14 Thread via GitHub


ChenChuangForLinux commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1564556600


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   This my final solution based on the original idea.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-07 Thread via GitHub


chenchuangchn commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1555010494


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   But in another case in rwb_writebuffer()(rwbuffer.c:367), startblock may be 
unalignment, it also just call rwb->wrflush(ftl_flush).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-07 Thread via GitHub


xiaoxiang781216 commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1554853308


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   No, ftl depends on the rwb alignment at all.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-07 Thread via GitHub


ChenChuangForLinux commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1554839997


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   Sorry, I'm busy today. Why not remove all unalignment issue handler in 
rwb_wrflush()? ftl layler has been done it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-07 Thread via GitHub


xiaoxiang781216 commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1554834154


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   After more thinking, it's hard to handle unalignment issue here when the 
cache is near full without additional buffer. So, I think the better approach 
may allocate the buffer with one additional aligned block, or ensure the 
startblock is aligned at the first place.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-06 Thread via GitHub


ChenChuangForLinux commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1554798912


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   Oh, you're right, it my fault. I will take a new PR in 3 hours. By the way, 
I don't think it't necessarily to use padblocks strategy in rwb_wrflush(), just 
call rwb->wrflush() is simple, since ftl layer has done enough precoess.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-06 Thread via GitHub


xiaoxiang781216 commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1554656121


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   Since wrnblocks may smaller than rwb->wrnblocks, [rwb->wrnblocks - 
wrnblocks, rwb->wrnblocks) is destroyed by memmove.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-06 Thread via GitHub


chenchuangchn commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1554632078


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);
   rwb->wrblockstart -= padblocks;
-  rwb->wrnblocks += padblocks;
+  rwb->wrnblocks -= wrnblocks;
   rwb_read_(rwb, rwb->wrblockstart, padblocks, rwb->wrbuffer);
+
+  ret = rwb->wrflush(rwb->dev, rwb->wrbuffer, rwb->wrblockstart,
+ padblocks + wrnblocks);

Review Comment:
   OK



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-06 Thread via GitHub


chenchuangchn commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1554631996


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   The padblocks + wrnblocks <= wralignblocks, why will the memmove destroy the 
content at the end?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-06 Thread via GitHub


acassis commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1554621902


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);
   rwb->wrblockstart -= padblocks;
-  rwb->wrnblocks += padblocks;
+  rwb->wrnblocks -= wrnblocks;
   rwb_read_(rwb, rwb->wrblockstart, padblocks, rwb->wrbuffer);
+
+  ret = rwb->wrflush(rwb->dev, rwb->wrbuffer, rwb->wrblockstart,
+ padblocks + wrnblocks);

Review Comment:
   ```suggestion
padblocks + wrnblocks);



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-06 Thread via GitHub


xiaoxiang781216 commented on code in PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#discussion_r1554582306


##
drivers/misc/rwbuffer.c:
##
@@ -140,18 +140,28 @@ static void rwb_wrflush(FAR struct rwbuffer_s *rwb)
   if (rwb->wrnblocks > 0)
 {
   size_t padblocks;
+  size_t wrnblocks;
 
   finfo("Flushing: blockstart=0x%08lx nblocks=%d from buffer=%p\n",
 (long)rwb->wrblockstart, rwb->wrnblocks, rwb->wrbuffer);
 
   padblocks = rwb->wrblockstart % rwb->wralignblocks;
   if (padblocks)
 {
+  wrnblocks = (rwb->wralignblocks - padblocks) < rwb->wrnblocks ?
+(rwb->wralignblocks - padblocks) : rwb->wrnblocks;
   memmove(rwb->wrbuffer + padblocks * rwb->blocksize,
-  rwb->wrbuffer, rwb->wrnblocks * rwb->blocksize);
+  rwb->wrbuffer, wrnblocks * rwb->blocksize);

Review Comment:
   but, memmove with partial block will destroy the content at the end, 
@ChenChuangForLinux .



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-05 Thread via GitHub


xiaoxiang781216 commented on PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#issuecomment-2040970781

   @ChenChuangForLinux please squash into one patch.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-05 Thread via GitHub


acassis commented on PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#issuecomment-2039747255

   @ChenChuangForLinux please check coding style issues:
   
   $ ./tools/checkpatch.sh -f drivers/misc/rwbuffer.c
   
   And fix the issues


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



Re: [PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-05 Thread via GitHub


ChenChuangForLinux commented on PR #12056:
URL: https://github.com/apache/nuttx/pull/12056#issuecomment-2039013658

   when the offest from rwb->wrblockstart to startblock plus rwb->wrnblocks is 
greater than rwb->wralignblocks, it will be causing memory overflow since 
rwb->wrbuffer is allocated rwb.wrmaxblock(rwb.wralignblocks) block_size bytes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[PR] fix: the bug about rwbuffer causing mem overflow [nuttx]

2024-04-04 Thread via GitHub


ChenChuangForLinux opened a new pull request, #12056:
URL: https://github.com/apache/nuttx/pull/12056

   when the offest from rwb->wrblockstart to startblock plus rwb->wrnblocks is 
greater than rwb->wralignblocks, it will be causing memory overflow since 
rwb->wrbuffer is allocated rwb.wrmaxblock(rwb.wralignblocks) bytes.
   
   ## Summary
   
   ## Impact
   
   ## Testing
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org