diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-08-31 14:25:18 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:36:15 -0500 |
commit | 06db5396966819b3124034d25d814cc0843bd6e9 (patch) | |
tree | fcfd76618e8e65ff063d7ca71c90075fcf335b89 /source4/scripting/ejs | |
parent | 181fde4729d9d7ae9677ec970c7bd7d9bd1455b3 (diff) | |
download | samba-06db5396966819b3124034d25d814cc0843bd6e9.tar.gz samba-06db5396966819b3124034d25d814cc0843bd6e9.tar.bz2 samba-06db5396966819b3124034d25d814cc0843bd6e9.zip |
r9825: Correctly handle length argument to substr()
(This used to be commit edf380cb5fa2c168fc05dd54580f024239ef835f)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r-- | source4/scripting/ejs/smbcalls_string.c | 5 |
1 files changed, 2 insertions, 3 deletions
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); |