-
Notifications
You must be signed in to change notification settings - Fork 8
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
Overzealous strnlen checking #7
Comments
Thanks for opening this issue. I think OpenOSC can add a new define flag to turn on/off the remapping of strnlen(): -DOPENOSC_STRNLEN_DISABLE By default, we will remap strnlen, but if you explicitly add the above flag in your CFLAGS, then we will disable strnlen() remapping, thus not throwing errors for strnlen(). what do you think? |
That would work, but it would be extra great if within the That would be ideal because I plan to put a workaround in place to allow our code to be compiled with OpenOSC enabled, and without requiring the person (or build system) doing the build to be aware of this and change their build system configuration: #if defined(__OPENOSC_H__)
# define strnlen_trunc(s, l) strlen(s)
#else
# define strnlen_trunc(s, l) strnlen(s, l)
#endif I then use my With your proposed solution, but also setting #if defined(__OPENOSC_H__) && !defined(OPENOSC_STRLEN_MAP_DISABLED)
# define strnlen_trunc(s, l) strlen(s)
# else
# define strnlen_trunc(s, l) strnlen(s, l)
#endif That way, if OpenOSC remapping of |
Sure, good idea. I will set OPENOSC_STRNLEN_MAP_DISABLED (or similar) if OPENOSC_STRNLEN_DISABLE is defined. I will add this in our next OpenOSC release. Thanks! |
@yonhan3
I have an application that would need quite a few modifications to build with OpenOSC, which I think shouldn't be necessary (or at least optional), since
strnlen
checking is, in my opinion, overzealous, and the modifications would make the program less understandable if not less secure.Take this code for example:
I can't see what the point is in raising an error here, at least not in all cases... this means that we'd need to have some code where truncation actually happens (or the size is exactly the same like) to not raise an error:
In my use case, I have code like this (that is used in example code). It conveys useful information both to the programmer that the MAX_STRING_LEN (as set in headers) is the maximum usable string length, and also to the program later, which can truncate strings to
len
later on.Replacing this kind of code with something like ...
... doesn't seem to be a great benefit (and now many IDE's won't show the user value of MAX_STRING_LEN because it is in a comment, etc.)
(Using strlen in all the cases where OpenOSC would complain is fine too, but isn't helpful when using strlen is banned by policy, along with the other non-
n
functions.)The text was updated successfully, but these errors were encountered: