Silence warnings by converting STRCPY to strncpy calls (#995)

STRCPY macro makes pointer comparison which creates a warning

In those places, replace the macro with `strncpy` with careful review of
destination buffer size

With this change I do not get compiler warnings at all
This commit is contained in:
Pavel Punsky 2022-09-30 08:17:46 -07:00 committed by GitHub
parent 05c0b6e34c
commit a3d338e2c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 7 deletions

View File

@ -233,7 +233,7 @@ redis_context_handle redisLibeventAttach(struct event_base *base, char *ip0, int
if(ip0 && ip0[0])
STRCPY(ip,ip0);
else
STRCPY(ip,"127.0.0.1");
strncpy(ip,"127.0.0.1",sizeof(ip));
int port = DEFAULT_REDIS_PORT;
if(port0>0)

View File

@ -189,7 +189,7 @@ redis_context_handle get_redis_async_connection(struct event_base *base, const c
if (co->host)
STRCPY(ip,co->host);
if (!ip[0])
STRCPY(ip,"127.0.0.1");
strncpy(ip,"127.0.0.1",sizeof(ip));
if (co->port)
port = (int) (co->port);
@ -298,7 +298,7 @@ static redisContext *get_redis_connection(void) {
if (co->host)
STRCPY(ip,co->host);
if (!ip[0])
STRCPY(ip,"127.0.0.1");
strncpy(ip,"127.0.0.1",sizeof(ip));
if (co->port)
port = (int) (co->port);

View File

@ -2075,7 +2075,7 @@ static int adminmain(int argc, char **argv)
#if !defined(TURN_NO_SQLITE)
if(!strlen(turn_params.default_users_db.persistent_users_db.userdb) && (turn_params.default_users_db.userdb_type == TURN_USERDB_TYPE_SQLITE))
STRCPY(turn_params.default_users_db.persistent_users_db.userdb,DEFAULT_USERDB_FILE);
strncpy(turn_params.default_users_db.persistent_users_db.userdb,DEFAULT_USERDB_FILE, TURN_LONG_STRING_SIZE);
#endif
if(ct == TA_COMMAND_UNKNOWN) {
@ -2426,7 +2426,7 @@ int main(int argc, char **argv)
#if !defined(TURN_NO_SQLITE)
if(!strlen(turn_params.default_users_db.persistent_users_db.userdb) && (turn_params.default_users_db.userdb_type == TURN_USERDB_TYPE_SQLITE))
STRCPY(turn_params.default_users_db.persistent_users_db.userdb,DEFAULT_USERDB_FILE);
strncpy(turn_params.default_users_db.persistent_users_db.userdb,DEFAULT_USERDB_FILE, TURN_LONG_STRING_SIZE);
#endif
argc -= optind;
@ -2979,7 +2979,7 @@ static void set_ctx(SSL_CTX** out, const char *protocol, const SSL_METHOD* metho
SSL_CTX_set_default_passwd_cb(ctx, pem_password_func);
if(!(turn_params.cipher_list[0]))
STRCPY(turn_params.cipher_list,DEFAULT_CIPHER_LIST);
strncpy(turn_params.cipher_list,DEFAULT_CIPHER_LIST,TURN_LONG_STRING_SIZE);
SSL_CTX_set_cipher_list(ctx, turn_params.cipher_list);
SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);

View File

@ -1557,7 +1557,8 @@ static ioa_socket_handle current_socket = NULL;
static char *get_bold_admin_title(void)
{
static char sbat[1025];
STRCPY(sbat,__bold_admin_title);
strncpy(sbat,__bold_admin_title,sizeof(sbat));
if(current_socket && current_socket->special_session) {
struct admin_session* as = (struct admin_session*)current_socket->special_session;
if(as->as_ok) {