From 06db5396966819b3124034d25d814cc0843bd6e9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 31 Aug 2005 14:25:18 +0000 Subject: r9825: Correctly handle length argument to substr() (This used to be commit edf380cb5fa2c168fc05dd54580f024239ef835f) --- source4/scripting/ejs/smbcalls_string.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/scripting') diff --git a/source4/scripting/ejs/smbcalls_string.c b/source4/scripting/ejs/smbcalls_string.c index e127cdf8af..66e2210ea8 100644 --- a/source4/scripting/ejs/smbcalls_string.c +++ b/source4/scripting/ejs/smbcalls_string.c @@ -155,6 +155,7 @@ static int ejs_substr(MprVarHandle eid, int argc, struct MprVar **argv) orig = mprToString(argv[0]); start_offset = mprToInt(argv[1]); + length = strlen(orig); if (start_offset < 0) start_offset += strlen(orig); if (start_offset < 0 || start_offset > strlen(orig)) { ejsSetErrorMsg(eid, "substr arg 2 out of bounds"); @@ -162,14 +163,12 @@ static int ejs_substr(MprVarHandle eid, int argc, struct MprVar **argv) } if (argc == 3) { - length = mprToInt(argv[1]); + length = mprToInt(argv[2]); if (length < 0) length += strlen(orig) - start_offset; if (length < 0 || length+start_offset > strlen(orig)) { ejsSetErrorMsg(eid, "substr arg 3 out of bounds"); return -1; } - } else { - length = strlen(orig); } target = talloc_strndup(mprMemCtx(), orig+start_offset, length); -- cgit