@@ -114,7 +114,7 @@ static int parse_cidr_entry(const char *cidr, int *family, unsigned char *networ
114114 if (strlen (cidr ) >= sizeof (entry )) {
115115 return -1 ;
116116 }
117- safe_strcpy (entry , cidr , sizeof (entry ));
117+ safe_strcpy (entry , cidr , sizeof (entry ), 0 );
118118
119119 char * trimmed = trim_ascii_whitespace (entry );
120120 if (!trimmed || trimmed [0 ] == '\0' ) {
@@ -194,7 +194,7 @@ static int normalize_allowed_login_cidrs(const char *allowed_login_cidrs,
194194 }
195195
196196 char input [USER_ALLOWED_LOGIN_CIDRS_MAX ];
197- safe_strcpy (input , allowed_login_cidrs , sizeof (input ));
197+ safe_strcpy (input , allowed_login_cidrs , sizeof (input ), 0 );
198198
199199 char * saveptr = NULL ;
200200 for (char * token = strtok_r (input , ",\n" , & saveptr );
@@ -309,18 +309,18 @@ static void populate_user_from_stmt(sqlite3_stmt *stmt, user_t *user) {
309309 memset (user , 0 , sizeof (* user ));
310310
311311 user -> id = sqlite3_column_int64 (stmt , 0 );
312- safe_strcpy (user -> username , (const char * )sqlite3_column_text (stmt , 1 ), sizeof (user -> username ));
312+ safe_strcpy (user -> username , (const char * )sqlite3_column_text (stmt , 1 ), sizeof (user -> username ), 0 );
313313
314314 const char * email = (const char * )sqlite3_column_text (stmt , 2 );
315315 if (email ) {
316- safe_strcpy (user -> email , email , sizeof (user -> email ));
316+ safe_strcpy (user -> email , email , sizeof (user -> email ), 0 );
317317 }
318318
319319 user -> role = (user_role_t )sqlite3_column_int (stmt , 3 );
320320
321321 const char * api_key = (const char * )sqlite3_column_text (stmt , 4 );
322322 if (api_key ) {
323- safe_strcpy (user -> api_key , api_key , sizeof (user -> api_key ));
323+ safe_strcpy (user -> api_key , api_key , sizeof (user -> api_key ), 0 );
324324 }
325325
326326 user -> created_at = sqlite3_column_int64 (stmt , 5 );
@@ -332,13 +332,13 @@ static void populate_user_from_stmt(sqlite3_stmt *stmt, user_t *user) {
332332
333333 const char * allowed_tags = (const char * )sqlite3_column_text (stmt , 11 );
334334 if (allowed_tags && allowed_tags [0 ] != '\0' ) {
335- safe_strcpy (user -> allowed_tags , allowed_tags , sizeof (user -> allowed_tags ));
335+ safe_strcpy (user -> allowed_tags , allowed_tags , sizeof (user -> allowed_tags ), 0 );
336336 user -> has_tag_restriction = true;
337337 }
338338
339339 const char * allowed_login_cidrs = (const char * )sqlite3_column_text (stmt , 12 );
340340 if (allowed_login_cidrs && allowed_login_cidrs [0 ] != '\0' ) {
341- safe_strcpy (user -> allowed_login_cidrs , allowed_login_cidrs , sizeof (user -> allowed_login_cidrs ));
341+ safe_strcpy (user -> allowed_login_cidrs , allowed_login_cidrs , sizeof (user -> allowed_login_cidrs ), 0 );
342342 user -> has_login_cidr_restriction = true;
343343 }
344344}
@@ -1864,9 +1864,9 @@ int db_auth_list_user_sessions(int64_t user_id, session_t *sessions, int max_cou
18641864 const char * token = (const char * )sqlite3_column_text (stmt , 2 );
18651865 const char * ip = (const char * )sqlite3_column_text (stmt , 7 );
18661866 const char * ua = (const char * )sqlite3_column_text (stmt , 8 );
1867- if (token ) safe_strcpy (session -> token , token , sizeof (session -> token ));
1868- if (ip ) safe_strcpy (session -> ip_address , ip , sizeof (session -> ip_address ));
1869- if (ua ) safe_strcpy (session -> user_agent , ua , sizeof (session -> user_agent ));
1867+ if (token ) safe_strcpy (session -> token , token , sizeof (session -> token ), 0 );
1868+ if (ip ) safe_strcpy (session -> ip_address , ip , sizeof (session -> ip_address ), 0 );
1869+ if (ua ) safe_strcpy (session -> user_agent , ua , sizeof (session -> user_agent ), 0 );
18701870 session -> created_at = sqlite3_column_int64 (stmt , 3 );
18711871 session -> last_activity_at = sqlite3_column_int64 (stmt , 4 );
18721872 session -> idle_expires_at = sqlite3_column_int64 (stmt , 5 );
@@ -2079,8 +2079,8 @@ int db_auth_list_trusted_devices(int64_t user_id, trusted_device_t *devices, int
20792079 device -> user_id = sqlite3_column_int64 (stmt , 1 );
20802080 const char * ip = (const char * )sqlite3_column_text (stmt , 5 );
20812081 const char * ua = (const char * )sqlite3_column_text (stmt , 6 );
2082- if (ip ) safe_strcpy (device -> ip_address , ip , sizeof (device -> ip_address ));
2083- if (ua ) safe_strcpy (device -> user_agent , ua , sizeof (device -> user_agent ));
2082+ if (ip ) safe_strcpy (device -> ip_address , ip , sizeof (device -> ip_address ), 0 );
2083+ if (ua ) safe_strcpy (device -> user_agent , ua , sizeof (device -> user_agent ), 0 );
20842084 device -> created_at = sqlite3_column_int64 (stmt , 2 );
20852085 device -> last_used_at = sqlite3_column_int64 (stmt , 3 );
20862086 device -> expires_at = sqlite3_column_int64 (stmt , 4 );
@@ -2188,7 +2188,7 @@ int db_auth_get_totp_info(int64_t user_id, char *secret, size_t secret_size, boo
21882188
21892189 const char * db_secret = (const char * )sqlite3_column_text (stmt , 0 );
21902190 if (db_secret && db_secret [0 ] != '\0' ) {
2191- safe_strcpy (secret , db_secret , secret_size );
2191+ safe_strcpy (secret , db_secret , secret_size , 0 );
21922192 }
21932193
21942194 * enabled = sqlite3_column_int (stmt , 1 ) != 0 ;
@@ -2398,7 +2398,7 @@ bool db_auth_ip_allowed_for_user(const user_t *user, const char *client_ip) {
23982398 }
23992399
24002400 char cidr_list [USER_ALLOWED_LOGIN_CIDRS_MAX ];
2401- safe_strcpy (cidr_list , user -> allowed_login_cidrs , USER_ALLOWED_LOGIN_CIDRS_MAX );
2401+ safe_strcpy (cidr_list , user -> allowed_login_cidrs , USER_ALLOWED_LOGIN_CIDRS_MAX , 0 );
24022402
24032403 char * saveptr = NULL ;
24042404 for (char * token = strtok_r (cidr_list , ",\n" , & saveptr );
@@ -2434,7 +2434,7 @@ bool db_auth_stream_allowed_for_user(const user_t *user, const char *stream_tags
24342434
24352435 // Tokenize stream_tags and check each against user's allowed_tags
24362436 char stream_copy [256 ];
2437- safe_strcpy (stream_copy , stream_tags , sizeof (stream_copy ));
2437+ safe_strcpy (stream_copy , stream_tags , sizeof (stream_copy ), 0 );
24382438
24392439 char * saveptr = NULL ;
24402440 char * token = strtok_r (stream_copy , "," , & saveptr );
0 commit comments