ref: 15ef29e7c0ceb678f39ac12ce40bdf3484a6423b
parent: b4fb12662da6de2f9853162572f4907b39943870
author: Tor Andersson <tor.andersson@artifex.com>
date: Fri Jan 2 08:47:56 EST 2015
Use memcpy instead of strcpy when copying short strings.
--- a/jsrun.c
+++ b/jsrun.c
@@ -107,7 +107,8 @@
CHECKSTACK(1);
if (n < 16) {
STACK[TOP].type = JS_TSHRSTR;
- strcpy(STACK[TOP].u.shrstr, v);
+ memcpy(STACK[TOP].u.shrstr, v, n);
+ STACK[TOP].u.shrstr[n] = 0;
} else {
STACK[TOP].type = JS_TMEMSTR;
STACK[TOP].u.memstr = jsV_newmemstring(J, v, n);
--- a/jsvalue.c
+++ b/jsvalue.c
@@ -284,7 +284,8 @@
int n = strlen(p);
if (n < 16) {
v->type = JS_TSHRSTR;
- strcpy(v->u.shrstr, p);
+ memcpy(v->u.shrstr, p, n);
+ v->u.shrstr[n] = 0;
return v->u.shrstr;
} else {
v->type = JS_TMEMSTR;