Off-by-one errors in string retrieval unit tests
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 128
- Forks
- 110
- Avg merge
- 5d 14h
- Merged PRs (30d)
- 10
Description
I don't think this affects production code..
A lot of our unit tests in which we retrieve the string, we don't take into account the extra byte needed for the NULL terminator character.
Take for example NI-FAKE unit test 'test_get_attribute_string'. We use len() to get the size of the string, and this is what the IVI dance returns. However, len() is off by one.
In mock_helper.py.mako, we cancel out the bug with another bug - we also use len() to determine the size to return and thus the size of the buffer our API allocates.
The fix is not as simple as adding 1, because we don't have different code paths for strings and other buffers which do not need the extra element.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the NI-FAKE test_get_attribute_string test and mock_helper.py.mako, then trace how len() determines the returned size and allocated buffer. Compare string retrieval with other buffer paths and verify that the tests cover the NULL terminator without masking a sizing mismatch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100