Repository navigation
Conversation
Several TACDev C API getters trusted the caller's index: - GetPortData() only checked deviceIndex against the upper bound, so a negative index was passed to QList::at() and crashed the host process (assert in debug, out-of-bounds read in release). - GetCommand() relied on commandEntry() returning pin 0 for a bad index, but it returns a default entry with pin -1, so an out-of-range index succeeded and produced a garbage ";;18446744073709551615;;;" entry instead of an error. - GetScriptVariable() did not check the index at all. Both now return TAC_BAD_INDEX with an empty buffer for an out-of-range index, the same as GetQuickCommand() already does. Existing callers iterate up to the reported count, so valid indexes behave exactly as before. GetHelpText() set *actualSize only when the buffer was too small. It now also reports the size on success, as the parameter name implies. Verified on a PSoC board: negative GetPortData indexes return 0 without crashing, out-of-range GetCommand/GetScriptVariable return TAC_BAD_INDEX, GetHelpText reports actualSize, and TacService, TACDump and the TAC GUI tools work unchanged. Signed-off-by: hangzqcom <hangz@qti.qualcomm.com>
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.
Problem
Several TACDev C API getters trusted the caller's index or left an out-parameter unset:
GetPortDatadeviceIndex = -1/-1000QList::at())GetCommandGetCommandCount();;18446744073709551615;;;GetScriptVariableGetScriptVariableCount()GetHelpText*actualSizeleft unset on successGetCommandrelied oncommandEntry()returning pin 0 for a bad index. It actually returns a default entry with pin -1, so the existing_pin != 0check passed.Change
GetPortData: also rejectdeviceIndex < 0, so it returns 0 like any other invalid index.GetCommand/GetScriptVariable: check the index against the count explicitly. Out of range now returnsTAC_BAD_INDEXwith an empty buffer, which is whatGetQuickCommandalready does.GetHelpText: set*actualSizeon success too, guarded by the existing null check.One file,
interfaces/C++/TACDev/TACDev.cpp. No header or ABI change.Valid indexes behave exactly as before. I checked the in-repo callers (C#, Python, Java and MCP examples, TACDump) and they all iterate up to the reported count. None loops until failure, so the new
TAC_BAD_INDEXreturn only affects calls that were already out of range.Verification
Tested on Windows with a PSoC board (FW 1.4.19.0), using this DLL in the installed tools folder.
GetPortData(-1)andGetPortData(-1000)return 0 and the process exits cleanly. Before, it crashed.GetCommand(out of range)andGetScriptVariable(out of range)returnTAC_BAD_INDEX(4) with an empty buffer.GetHelpTextreportsactualSize = 1363, matching the returned length.Overall: 165 pass, 0 fail. Before this change the same run had 7 failures, all covered by the table above.