mirror of
https://github.com/UberGames/GtkRadiant.git
synced 2024-11-10 06:31:41 +00:00
q3map2: add safe string copy functions
* Q_strncpyz() * Q_strncat() * Q_strcat() Guard against buffer overruns, always zero terminate the result.
This commit is contained in:
parent
997811d430
commit
c2be26a9bd
2 changed files with 37 additions and 0 deletions
|
@ -46,6 +46,38 @@ vec_t Random( void ){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *Q_strncpyz( char *dst, const char *src, size_t len ) {
|
||||||
|
if ( len == 0 ) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy( dst, src, len );
|
||||||
|
dst[ len - 1 ] = '\0';
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *Q_strcat( char *dst, size_t dlen, const char *src ) {
|
||||||
|
size_t n = strlen( dst );
|
||||||
|
|
||||||
|
if ( n > dlen ) {
|
||||||
|
abort(); /* buffer overflow */
|
||||||
|
}
|
||||||
|
|
||||||
|
return Q_strncpyz( dst + n, src, dlen - n );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
|
||||||
|
size_t n = strlen( dst );
|
||||||
|
|
||||||
|
if ( n > dlen ) {
|
||||||
|
abort(); /* buffer overflow */
|
||||||
|
}
|
||||||
|
|
||||||
|
return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ExitQ3Map()
|
ExitQ3Map()
|
||||||
|
|
|
@ -83,6 +83,8 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------------
|
||||||
|
@ -1446,6 +1448,9 @@ surfaceInfo_t;
|
||||||
|
|
||||||
/* main.c */
|
/* main.c */
|
||||||
vec_t Random( void );
|
vec_t Random( void );
|
||||||
|
char *Q_strncpyz( char *dst, const char *src, size_t len );
|
||||||
|
char *Q_strcat( char *dst, size_t dlen, const char *src );
|
||||||
|
char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen );
|
||||||
int BSPInfo( int count, char **fileNames );
|
int BSPInfo( int count, char **fileNames );
|
||||||
int ScaleBSPMain( int argc, char **argv );
|
int ScaleBSPMain( int argc, char **argv );
|
||||||
int ConvertMain( int argc, char **argv );
|
int ConvertMain( int argc, char **argv );
|
||||||
|
|
Loading…
Reference in a new issue