summaryrefslogtreecommitdiffstats
path: root/apps/menu.c
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2007-11-16 08:18:08 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2007-11-16 08:18:08 +0000
commit34d08b235e54571fa00e0ae2fdbee5540f8b189c (patch)
tree3a1f592356192294faac6757577de58820bb65c1 /apps/menu.c
parent7197d9dde7bb4f1476eb82318c1253982fc9e620 (diff)
downloadrockbox-34d08b235e54571fa00e0ae2fdbee5540f8b189c.tar.gz
rockbox-34d08b235e54571fa00e0ae2fdbee5540f8b189c.tar.bz2
rockbox-34d08b235e54571fa00e0ae2fdbee5540f8b189c.zip
Fix buffer overflow in the title padding code (FS#8163)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15633 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/menu.c')
-rw-r--r--apps/menu.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/apps/menu.c b/apps/menu.c
index 75f62565ca..6ab57ad061 100644
--- a/apps/menu.c
+++ b/apps/menu.c
@@ -24,6 +24,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include "config.h"
+#include "system.h"
#include "lcd.h"
#include "font.h"
@@ -288,8 +289,9 @@ bool do_setting_from_menu(const struct menu_item_ex *temp)
else
title = ID2P(setting->lang_id);
- /* this is needed so the scroll settings title
- can actually be used to test the setting */
+ /* Pad the title string by repeating it. This is needed
+ so the scroll settings title can actually be used to
+ test the setting */
if (setting->flags&F_PADTITLE)
{
int i = 0, len;
@@ -298,11 +300,11 @@ bool do_setting_from_menu(const struct menu_item_ex *temp)
else
title = P2STR((unsigned char*)title);
len = strlen(title);
- while (i<MAX_PATH)
+ while (i < MAX_PATH-1)
{
- strncpy(&padded_title[i], title,
- len<MAX_PATH-1-i?len:MAX_PATH-1-i);
- i += len;
+ int padlen = MIN(len, MAX_PATH-1-i);
+ strncpy(&padded_title[i], title, padlen);
+ i += padlen;
if (i<MAX_PATH-1)
padded_title[i++] = ' ';
}