[BUGFIX] pluginlib kbd_helper.c buffer ovfl

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 1194a968bda4c5764d230ce89d0076ea500904b0
Author: William Wilgus <[email protected]>
Date:   Fri Jan 23 21:52:42 2026 -0500

    [BUGFIX] pluginlib kbd_helper.c buffer ovfl
    
    sizeof is in bytes len counts as a ucschar
    should also be added to total_len
    
    yep buffer ovfl
    
    Change-Id: Ibebb8574e6dbab0ca78d1cdfeb04cbbda38f05e9

diff --git a/apps/plugins/announce_status.c b/apps/plugins/announce_status.c
index 203ac55a46..cd0482f500 100644
--- a/apps/plugins/announce_status.c
+++ b/apps/plugins/announce_status.c
@@ -70,7 +70,7 @@ static const char keybd_layout[] =
  * - \n does not create a key, but it also consumes one element
  * - the final null terminator is equivalent to \n
  * - since sizeof includes the null terminator we don't need +1 for that. */
-static ucschar_t kbd_buf[sizeof(keybd_layout)];
+static ucschar_t kbd_buf[sizeof(keybd_layout) + 1];
 
 /****************** prototypes ******************/
 void print_scroll(char* string); /* implements a scrolling screen */
diff --git a/apps/plugins/lib/kbd_helper.c b/apps/plugins/lib/kbd_helper.c
index 0f7bbff8f7..90ed165fcd 100644
--- a/apps/plugins/lib/kbd_helper.c
+++ b/apps/plugins/lib/kbd_helper.c
@@ -36,12 +36,11 @@
 */
 int kbd_create_layout(const char *layout, ucschar_t *buf, int bufsz)
 {
-    ucschar_t *pbuf;
+    ucschar_t *pbuf = buf;
     const unsigned char *p = layout;
     int len = 0;
     int total_len = 0;
-    pbuf = buf;
-    while (*p && (pbuf - buf + (ptrdiff_t) sizeof(ucschar_t)) < bufsz)
+    while (*p && (pbuf - buf + (ptrdiff_t) sizeof(*buf)) < bufsz)
     {
         p = rb->utf8decode(p, &pbuf[len+1]);
         if (pbuf[len+1] == '\n')
@@ -55,13 +54,14 @@ int kbd_create_layout(const char *layout, ucschar_t *buf, int bufsz)
             len++;
     }
 
-    if (len+1 < bufsz)
+    if ((total_len + len + 1) * sizeof(*buf) < bufsz)
     {
         *pbuf = len;
         pbuf[len+1] = 0xFEFF;   /* mark end of characters */
         total_len += len + 1;
-        return total_len * sizeof(ucschar_t);
+        return total_len * sizeof(*buf);
     }
 
+    //rb->logf("%s %d %d\n", __func__, bufsz, (total_len + len + 1) * sizeof(*buf));
     return 0;
 }
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.