Repository navigation
fix: resolve out-of-bounds reads, uninitialized decfrac scaling, string termination, and lock handling - #43
Open
xPuffyPuffx wants to merge 1 commit into
Open
xPuffyPuffx wants to merge 1 commit into
xPuffyPuffx wants to merge 1 commit into
Conversation
…uffer handling - Replace strchr with memchr in thingset_get_object_by_path to prevent reading past length-delimited CBOR strings. - Initialize decfrac decode variables and check zcbor status before scaling mantissa to prevent uninitialized loop execution. - Add null-termination to unescaped JSON strings in txt_deserialize_value. - Release ts->lock on unsupported format in thingset_export_subsets. - Fix sizeof(pointer) and accumulated size checks in type name helpers.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While running unit conformance tests and fuzzing passes with Clang AddressSanitizer (
CONFIG_ASAN=y) and UndefinedBehaviorSanitizer (CONFIG_UBSAN=y), we identified several edge-case handling bugs across CBOR/JSON deserialization and helper functions:Bounds-checked path traversal for CBOR strings (
thingset.c:626):CBOR text strings decoded via
zcbor_tstr_decodeare length-delimited (path_len) and not null-terminated. Inthingset_get_object_by_path(), callingend = strchr(start, '/')when evaluating the leaf component (no trailing'/') scanned pastpath + path_leninto adjacent memory.Fix: Replaced
strchr(start, '/')withmemchr(start, '/', path + path_len - start).Check zcbor decode status in
DECFRACdeserialization (thingset_bin.c:606):If a
DECFRAC(CBOR Tag 4) payload list is malformed (e.g. empty list0xC4 0x80),zcbor_list_start_decode()fails, settingsuccess = false. Becauseexponent_receivedandmantissa_tmpwere decoded via short-circuitingsuccess && ..., they remained uninitialized on the stack. The scalingforloops and*mantissa = mantissa_tmpexecuted unconditionally using uninitialized stack values.Fix: Initialized temporary variables to zero and wrapped the scaling loop and assignment inside
if (success).Null-terminate unescaped JSON strings (
thingset_txt.c:612):Under
CONFIG_THINGSET_JSON_STRING_ESCAPING=y, character unescaping (\",\/, etc.) wrote intodata.str[data_pos++]but omitted writing a trailing\0. If an unescaped string was shorter than the previous contents of the buffer, residual characters from previous writes remained visible.Fix: Added
data.str[data_pos] = '\0';immediately after loop completion.Release context semaphore on unsupported export format (
thingset.c:197):thingset_export_subsets()acquiresk_sem_take(&ts->lock, ...). If an unsupported format enum is passed, thedefault:branch returned-THINGSET_ERR_NOT_IMPLEMENTEDwithout callingk_sem_give(&ts->lock), causing subsequent context operations to block indefinitely on lock timeout.Fix: Added
k_sem_give(&ts->lock);before returning fromdefault:.Fix buffer bounds calculations in
thingset_get_type_nameandget_function_arg_types(thingset.c:797, 811):thingset_get_type_name(),sizeof(elementType) > sizeevaluatedsizeof(char *)(4 or 8 bytes) instead ofstrlen(elementType) + 3 > size.get_function_arg_types(),if (total_len > size)compared accumulated total bytes against the remaining buffer capacity (sizedecremented bylen).Verification
All existing and boundary unit tests pass cleanly under
native_sim/native/64withCONFIG_ASAN=yandCONFIG_UBSAN=y: Running TESTSUITE thingset_audit_core ... PASS Running TESTSUITE thingset_bin ... PASS Running TESTSUITE thingset_txt ... PASS PROJECT EXECUTION SUCCESSFUL