-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing size of nvflag
in struct Namval
breaks things
#1038
Comments
Running this on macOS results in the "double-free" ASAN failure shown below:
The
|
I verified that changing the size of the |
Very curious. Adding padding to either side of the |
Bingo! I added a strategic printf to line 292 in cd_pwd.c to display the
Which is only meant to be passed as a flag to |
OMFG! See the Worse is there are two non-nvflag symbols that are valid in an unsigned short:
The former corresponds to There are likely other places in the code which assumes such value truncations on assignment will silently strip unwanted bits. |
That turns out not to be true. There are at least three places, and probably more, where |
This code is a white hot mess. Consider this definition src/cmd/ksh93/include/name.h:
Yet its related symbol is in src/cmd/ksh93/include/nval.h:
Those two symbols should be in the same header (nval.h). And that is true for all other |
Another OMFG bogosity. This symbol is meant to only be used as a flag to
See This explains why so many bugs are being found by ASAN, Coverity Scan, and debug malloc implementations. The writers of this code were being far too clever. The situation wouldn't be nearly as bad had they used proper interfaces that validated their arguments rather than preprocessor macros. |
FWIW, My intent is to widen |
I confirmed that the only places that modify Line 1371 in 1cf4ed0
Note the masking with ast/src/cmd/ksh93/include/name.h Lines 562 to 563 in 1cf4ed0
That is the sole use of the symbol. The intent appears to be to ensure those specific attrs are not turned when the aforementioned
That only some of the |
I pondered the code I mentioned in my previous comment some more. It is clear the only reason it also masks out the symbols that are otherwise legal in a nvflag is because they are aliased to symbols that only have meaning when calling |
Also, |
This commit refactors the local builtin to take advantage of some changes I intend to submit later as separate pull requests. These are: - np->nvflags has been expanded from 16-bit to 32-bit. This fixes the longstanding limitation detailed in a previous ksh2020 bug: att#1038. The fix consists of masking out nv_open-centric flags with explicit uses of the new NV_OPENMASK, rather than implicitly and obtusely abusing the limitations of unsigned short types. Here, I take advantage of it for storing NV_DYNAMIC in np->nvflags and using it from there, which is a safer and more simple choice long term. - A bugfix from ksh93v- 2012-08-24 has been backported to fix a potential segfault that is triggered under ASan when changing the sizes of np->nvsize and np->nvflags to uint32_t. This cannot be triggered on the dev branch, but I will submit this individually soon enough. (I would have already submitted it had I not been forced to deal with a broken PSU shortly after submitting ksh93#805; 0 out of 10 experience don't recommend). - Updated comment regarding pitfalls in the ksh93v- and current implementation of local. In any case I intend to separate out various fixes from this branch and submit them as separate pull requests, if only to eventually reduce the scope of this one to just the local builtin and nothing else (the sh_funscope refactor for instance fixes an out of bounds bug that has been on the dev branch for far too long). Unfortunately my life has been quite hellish lately, so there is no ETA yet.
The discussion about support for JSON in issue #820 notes that symbols
NV_JSON
andNV_JSON_LAST
are aliases for other symbols. Which is dangerous and shouldn't be necessary. So I opened PR #1037 to start work on eliminating such aliases. The next step in that cleanup is to change the definition ofstruct Namval
membernvflag
to be wider than anunsigned short
. However turning it into a 32 bit unsigned int breaks unit tests. Even with no changes to the bit field symbols.That should be impossible. That is, the size of that bit field should have zero effect on the behavior of the code as long as the size is wide enough to accommodate all bit values stored in that structure member. And converting from
unsigned short
(16 bits) touint32_t
(32 bits) is guaranteed to satisfy that constraint. This diff breaks 18 unit tests on macOS that pass without this change:Something is seriously wrong with the code that allocates or uses a
struct Namval
. The aforementioned change should have zero effect on the behavior of the code other than the amount of memory used.The text was updated successfully, but these errors were encountered: