-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
Fix OpenArena on glibc 2.37+ and replace all strncpy calls #659
base: main
Are you sure you want to change the base?
Conversation
It can't overflow because buff and text have the same max length (1024 and MAX_TOKENLENGTH).
macOS (targeting newer SDKs) and glibc 2.37 changes broke overlapping strncpy() used by OpenArena 0.8.8 QVMs. (Technically it was undefined behavior.) Add Q_strncpy() by Eugene C. from Quake3e that allows overlapping dest and src for QVM strncpy syscalls. I made Q_strncpyz() use it for consistency and made QVMs remap the Q_strncpy() call to the strncpy syscall in case there is a better idea of how to handle strncpy in the future. Try to handle strncpy the same in QVMs and DLLs.
|
ioquake/ioq3#659 remapping strncpy to the new Q_strncpy is still missing
I'm implemented both char *Q_strncpy( char *dest, char *src, int destsize )
{
char *s = src, *start = dest;
int src_len;
while ( *s != '\0' )
++s;
src_len = (int)(s - src);
if ( src_len > destsize ) {
src_len = destsize;
}
destsize -= src_len;
if ( dest > src && dest < src + src_len ) {
int i;
#ifdef _DEBUG
Com_Printf( S_COLOR_YELLOW "Q_strncpy: overlapped (dest > src) buffers\n" );
#endif
for ( i = src_len - 1; i >= 0; --i ) {
dest[i] = src[i]; // back overlapping
}
dest += src_len;
} else {
#ifdef _DEBUG
if ( src >= dest && src < dest + src_len ) {
Com_Printf( S_COLOR_YELLOW "Q_strncpy: overlapped (src >= dst) buffers\n" );
#ifdef _MSC_VER
// __debugbreak();
#endif
}
#endif
while ( src_len > 0 ) {
*dest++ = *src++;
--src_len;
}
}
while ( destsize > 0 ) {
*dest++ = '\0';
--destsize;
}
return start;
} it is longer than any suggested/existing version but fully inline and do not have any references to external functions like If you want to use it in QVM code then you should replace all post-increment assignments like |
Thank you. I don't compile it in QVMs, it's only called it through the strncpy syscall. |
macOS (targeting newer SDKs) and glibc 2.37 changes broke overlapping dest and src in strncpy() used by OpenArena 0.8.8 QVMs. (Technically it was undefined behavior.)
Add Q_strncpy() by Eugene C. from Quake3e that allows overlapping dest and src for QVM strncpy syscalls.
I made everything use Q_strncpyz and it use the new Q_strncpy function. I made QVMs remap the Q_strncpy call to the strncpy syscall in case there is a better idea of how to handle it in the future. I tried to make "strncpy" behave the same in QVMs and DLLs.
Also fix a CGame network buffer overflow due to mishandling of strncpy. NUL terminator is great but it's better when it's in the destination buffer.
Fixes #639.