 |
|
|
12-24-2021, 05:00 AM
|
#1
|
Human being with feelings
Join Date: Jul 2009
Posts: 3,714
|
Extension API: in parameter pair "char* buf" "int buf_sz", size is incorrect
If an extension registers a function with a pair of parameters named "const char* something" and "int something_sz", REAPER recognizes these parameters as a linked pair. The script only has to supply the char* argument, and REAPER itself supplies the value of something_sz.
However, the value that REAPER supplies doesn't seem to be correct or useful. It seems to be calculated as one less than the number of characters before the first \0 char (unless \0 is the first character, in which case it is calculated differently).
It would be much more useful if REAPER passes the exact char length of the string (including all internal and terminal \0 chars). This would allow the extension to read the entire string without fears of memory access violations.
At present, in order for the extension to know the true length of a string argument, the script/user has to supply the length as a separate argument.
|
|
|
12-24-2021, 05:10 AM
|
#2
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 13,986
|
A string in many languages including C/C++ (but not Lua) is just a pointer to a string of characters, with no intrinsic length information. The standard C strlen function simply counts characters until the first 0 is seen. If a string contains more information beyond the first 0 character, that has to be specified by whoever created the string, there's no way for the receiver to know.
|
|
|
12-24-2021, 06:18 AM
|
#3
|
Human being with feelings
Join Date: Oct 2007
Location: home is where the heart is
Posts: 11,610
|
This helps maybe?
https://forum.cockos.com/showthread....08#post2055208
edit:
Sorry, that's about out parameters, not in parameters.
Last edited by nofish; 12-24-2021 at 06:28 AM.
|
|
|
12-25-2021, 12:31 PM
|
#4
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 14,869
|
Edit: ah yes, there's some bugs in this, fixing!
Last edited by Justin; 12-25-2021 at 12:39 PM.
|
|
|
04-14-2022, 04:52 PM
|
#5
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,191
|
Scripts are allowed to set the size parameter bigger than the buffer:
Code:
// void Foo(const char *buf, int buf_sz)
reaper.Foo('a\0b\0', 1<<31) -- buffer over-read/crash
Last edited by cfillion; 04-16-2022 at 03:44 PM.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 04:03 AM.
|