summaryrefslogtreecommitdiffstats
path: root/apps/settings.c
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-11-07 23:29:59 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2019-01-08 03:44:32 +0100
commit3f6fed8eca790138e9ac80cb3b38b6791269982b (patch)
tree4ffecef8f41f31e18557a4a90449da85ddade306 /apps/settings.c
parentd24edc605b9b52d3610efbb9cf691c437ea00746 (diff)
downloadrockbox-3f6fed8eca790138e9ac80cb3b38b6791269982b.tar.gz
rockbox-3f6fed8eca790138e9ac80cb3b38b6791269982b.tar.bz2
rockbox-3f6fed8eca790138e9ac80cb3b38b6791269982b.zip
Fix potential buffer overflow in settings.c
Change-Id: Ie8953e3ffc5188685f1ea056863bfbdb817080a7
Diffstat (limited to 'apps/settings.c')
-rw-r--r--apps/settings.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/apps/settings.c b/apps/settings.c
index 9f3047e9df..2d38c4a5ef 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -402,8 +402,8 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len)
strlcpy(buf, start, buf_len);
else
{
- int len = (buf_len > (end-start))? end-start: buf_len;
- strlcpy(buf, start, len+1);
+ int len = MIN(buf_len, (end-start) + 1);
+ strlcpy(buf, start, len);
}
return true;
}
@@ -430,8 +430,8 @@ bool cfg_int_to_string(int setting_id, int val, char* buf, int buf_len)
strlcpy(buf, start, buf_len);
else
{
- int len = (buf_len > (end-start))? end-start: buf_len;
- strlcpy(buf, start, len+1);
+ int len = MIN(buf_len, (end-start) + 1);
+ strlcpy(buf, start, len);
}
return true;
}
@@ -494,8 +494,11 @@ bool cfg_to_string(int i/*setting_id*/, char* buf, int buf_len)
settings[i].filename_setting->suffix);
}
}
- else strlcpy(buf,(char*)settings[i].setting,
- settings[i].filename_setting->max_len);
+ else
+ {
+ int len = MIN(buf_len, settings[i].filename_setting->max_len);
+ strlcpy(buf,(char*)settings[i].setting,len);
+ }
break;
} /* switch () */
return true;