-
Notifications
You must be signed in to change notification settings - Fork 104
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
Long names can cause crashes or redefinition warnings. #169
Comments
I assume this is the name length field, with flags as the top bits? What's FLAG_PRECEDENCE used for? |
I'm not sure why it's crashing, but it seems like that the names being bigger than 31 characters is causing the problem, and there is no warning in place to detect this problem. For the moment I think I'm going to comment out FLAG_PRECEDENCE, and move FLAG_SMUDGE into that location. /* #define FLAG_PRECEDENCE (0x80) */ I'll also need to alter the forth version in 31 constant LV_MAX_CHARS \ maximum number of letters in name : ID. ( nfa -- ) inside : F?.SEARCH.NFA : N>NEXTLINK ( nfa -- nextlink , traverses name field ) inside ffFindNFA() This : PARTIAL.MATCH.NAME ( $str1 nfa -- flag , is $str1 in nfa ??? ) inside |
Probably best to extend these as well... void CreateDicEntryC( ExecToken XT, const char *CName, ucell_t Flags ) void CreateDicEntryC( ExecToken XT, const char *CName, ucell_t Flags ) static void CreateDeferredC( ExecToken DefaultXT, const char *CName ) |
So all the redefinition warnings are gone. zsh: segmentation fault pforth/platforms/unix/pforth_standalone run it under lldb Process 49215 stopped
|
NOTE: c-function is currently defined as: line 92 looks like this:
|
How is the TIB at 00x0000000_1_40f0a218 but the td_SourcePtr is at (char *) 0x0000000040f0a218 ? The lower 32 bits being the same can't be a coincidence... |
Lines immediately before this crash (this was generated by setting
|
Build and linked with -g -fsanitize=address ==57945==ERROR: AddressSanitizer: heap-use-after-free on address 0x6100000005d8 at pc 0x000100010104 bp 0x00016fdfe130 sp 0x00016fdfe128 (allocated and freed tables not helpful) (lldb) p gCurrentTask->td_SourcePtr |
In the function:
The line at the end: Has a zero setting in the wrong place - potentially past the end of the buffer: This should either be |
Pull request raised for segmentation fault. |
I have a change a branch of my fork that gives 63 length names. If you are interested in this, or in my making it switchable - so that it's 31 by default or 63 by compilation, then let me know. |
@robzed - Great detective work! Thanks so much for finding that p[len] bug. Also I am interested in the 63 character names as an option. I need to think about that FLAG_PRECEDENCE. |
Give me a few days, and I'll look at making a PR for the optional name size - along with some warning about long names. |
The crash from p[lan] is fixed. |
I looked into the FLAG_PRECEDENCE bit. I found mention of a "precedence bit" on the Forth Inc site. They seem to use the "precedence bit" the way we use FLAG_IMMEDIATE. But note that this will break the compatibility between pForth executable and saved pForth dictionary files! |
Added #182 Name to long warnings/errors to be raised as a separate PR. |
I'm adding to pForth to make it able to use SDL. I'm creating a C function bindings (rf_custom.c style) and then add add forth words to complete this so that I can use SDL2 from pForth. (This is based on ProgrammingRainbow gForth's work).
The custom c function bindings all work. I'm not adding constants and structures in Forth. The problem appears with constants like this one:
#3 constant SDL_THREAD_PRIORITY_TIME_CRITICAL
Some of the names in SDL are very long:
"SDL_THREAD_PRIORITY_TIME_CRITICAL" 33 bytes
"SDL_THREAD_PTHREAD_RECURSIVE_MUTEX" 34 bytes
"SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH" 33 bytes
"SDL_AUDIO_ALLOW_FREQUENCY_CHANGE" 32 bytes
NOTE: These are not the only ones... just the ones that were causing redefinition warnings.
For all of them (all constant), I got redefinition warnings. Some other long names I haven't.
For the last one I get a crash:
include added 896 bytes,28292 left.
Include SDL2/SDL_audio.fs
SDL_AUDIO_ALLOW_FREQUENCY_CHANGE redefined.
zsh: segmentation fault /Users/rob/Current_Projects/pForth/pforth/platforms/unix/pforth_standalone
I also notice that
1 constant SDL_AUDIO_ALLOW_FREQUENCY
Appears correctly in the dictionary as
words SDL_AUDIO_ALLOW_FREQUENCY
<>>
I also notice that
1 constant SDL_AUDIO_ALLOW_FREQUENCY_CHANGE123456789 ok
Appears in the dictionary as
words SDL_AUDIO SDL_AUDIO_ALLOW_FREQUENCY
<>
So in summary:
The text was updated successfully, but these errors were encountered: