This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit b75412d96ab4c9f08c0b913e90d3ae761b2620a8
Author: Xu Xingliang <[email protected]>
AuthorDate: Fri Apr 12 22:12:12 2024 +0800

    libc/base64: check buffer overflow for last char
    
    Signed-off-by: Xu Xingliang <[email protected]>
---
 libs/libc/net/lib_base64.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libs/libc/net/lib_base64.c b/libs/libc/net/lib_base64.c
index 039ffbdad3..91a39cd95a 100644
--- a/libs/libc/net/lib_base64.c
+++ b/libs/libc/net/lib_base64.c
@@ -83,7 +83,12 @@ int b64_ntop(FAR const unsigned char *src, size_t srclen,
       *target++ = g_pad64;
     }
 
-  *target = '\0';
+  if (datalen >= targsize)
+    {
+      return -1;
+    }
+
+  *target = '\0'; /* Returned length doesn't include '\0' */
   return datalen;
 }
 

Reply via email to