diff options
author | Mason Jones <20848827+smj-edison@users.noreply.github.com> | 2025-04-21 21:01:28 -0700 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2025-04-22 04:54:23 +0000 |
commit | f659fc4ec46f34c5c4a59a3f2223db6463e1d97d (patch) | |
tree | 029602d6cbbf38b245ebc6bbe9fb7f1a14bd97e5 /jim.c | |
parent | 9eaf6be68bade1f74302b78cd8c2f68fddf20442 (diff) | |
download | jimtcl-master.zip jimtcl-master.tar.gz jimtcl-master.tar.bz2 |
Currently jimtcl compares each element of `errorCode` against each `match` element.
But, it doesn't account for the situation where `errorCode` is shorter than `match`.
In this case the match should always fail (rather than segfaulting).
Diffstat (limited to 'jim.c')
-rw-r--r-- | jim.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -15023,16 +15023,22 @@ wrongargs: } else if (errorCodeObj) { int len = Jim_ListLength(interp, argv[idx + 1]); - int i; - - ret = JIM_OK; - /* Try to match the sublist against errorcode */ - for (i = 0; i < len; i++) { - Jim_Obj *matchObj = Jim_ListGetIndex(interp, argv[idx + 1], i); - Jim_Obj *objPtr = Jim_ListGetIndex(interp, errorCodeObj, i); - if (Jim_StringCompareObj(interp, matchObj, objPtr, 0) != 0) { - ret = -1; - break; + + if (len > Jim_ListLength(interp, errorCodeObj)) { + /* More elements in the sublist than in the errorCode so we can't match */ + ret = -1; + } + else { + int i; + ret = JIM_OK; + /* Try to match the sublist against errorcode */ + for (i = 0; i < len; i++) { + Jim_Obj *matchObj = Jim_ListGetIndex(interp, argv[idx + 1], i); + Jim_Obj *objPtr = Jim_ListGetIndex(interp, errorCodeObj, i); + if (Jim_StringCompareObj(interp, matchObj, objPtr, 0) != 0) { + ret = -1; + break; + } } } } |