@@ -307,17 +307,17 @@ void load_default_config(config_t *config) {
307307 }
308308
309309 // General settings
310- snprintf (config -> pid_file , MAX_PATH_LENGTH , "/var/run/lightnvr.pid" );
311- snprintf (config -> log_file , MAX_PATH_LENGTH , "/var/log/lightnvr.log" );
310+ safe_strcpy (config -> pid_file , "/var/run/lightnvr.pid" , MAX_PATH_LENGTH , 0 );
311+ safe_strcpy (config -> log_file , "/var/log/lightnvr.log" , MAX_PATH_LENGTH , 0 );
312312 config -> log_level = LOG_LEVEL_INFO ;
313313
314314 // Syslog settings
315315 config -> syslog_enabled = false;
316- snprintf (config -> syslog_ident , sizeof (config -> syslog_ident ), "lightnvr" );
316+ safe_strcpy (config -> syslog_ident , "lightnvr" , sizeof (config -> syslog_ident ), 0 );
317317 config -> syslog_facility = LOG_USER ;
318318
319319 // Storage settings
320- snprintf (config -> storage_path , MAX_PATH_LENGTH , "/var/lib/lightnvr/recordings" );
320+ safe_strcpy (config -> storage_path , "/var/lib/lightnvr/recordings" , MAX_PATH_LENGTH , 0 );
321321 config -> storage_path_hls [0 ] = '\0' ; // Empty by default, will use storage_path if not specified
322322 config -> max_storage_size = 0 ; // 0 means unlimited
323323 config -> retention_days = 30 ;
@@ -328,35 +328,35 @@ void load_default_config(config_t *config) {
328328
329329 // MP4 recording settings
330330 config -> record_mp4_directly = false;
331- snprintf (config -> mp4_storage_path , sizeof ( config -> mp4_storage_path ), "/var/lib/lightnvr/recordings/mp4" );
331+ safe_strcpy (config -> mp4_storage_path , "/var/lib/lightnvr/recordings/mp4" , sizeof ( config -> mp4_storage_path ), 0 );
332332 config -> mp4_segment_duration = 900 ; // 15 minutes
333333 config -> mp4_retention_days = 30 ;
334334
335335 // Models settings
336- snprintf (config -> models_path , MAX_PATH_LENGTH , "/var/lib/lightnvr/models" );
336+ safe_strcpy (config -> models_path , "/var/lib/lightnvr/models" , MAX_PATH_LENGTH , 0 );
337337
338338 // API detection settings
339- snprintf (config -> api_detection_url , MAX_URL_LENGTH , "http://localhost:8000/detect" );
340- snprintf (config -> api_detection_backend , 32 , "onnx" ); // Default to ONNX backend
339+ safe_strcpy (config -> api_detection_url , "http://localhost:8000/detect" , MAX_URL_LENGTH , 0 );
340+ safe_strcpy (config -> api_detection_backend , "onnx" , 32 , 0 ); // Default to ONNX backend
341341
342342 // Global detection defaults
343343 config -> default_detection_threshold = 50 ; // 50% confidence threshold
344344 config -> default_pre_detection_buffer = 5 ; // 5 seconds before detection
345345 config -> default_post_detection_buffer = 10 ; // 10 seconds after detection
346- snprintf (config -> default_buffer_strategy , 32 , "auto" ); // Auto-select buffer strategy
346+ safe_strcpy (config -> default_buffer_strategy , "auto" , 32 , 0 ); // Auto-select buffer strategy
347347
348348 // Database settings
349- snprintf (config -> db_path , MAX_PATH_LENGTH , "/var/lib/lightnvr/lightnvr.db" );
349+ safe_strcpy (config -> db_path , "/var/lib/lightnvr/lightnvr.db" , MAX_PATH_LENGTH , 0 );
350350 config -> db_backup_interval_minutes = 60 ;
351351 config -> db_backup_retention_count = 24 ;
352352 config -> db_post_backup_script [0 ] = '\0' ;
353353
354354 // Web server settings
355355 config -> web_port = 8080 ;
356- snprintf (config -> web_bind_ip , 32 , "0.0.0.0" );
357- snprintf (config -> web_root , MAX_PATH_LENGTH , "/var/lib/lightnvr/www" );
356+ safe_strcpy (config -> web_bind_ip , "0.0.0.0" , 32 , 0 );
357+ safe_strcpy (config -> web_root , "/var/lib/lightnvr/www" , MAX_PATH_LENGTH , 0 );
358358 config -> web_auth_enabled = true;
359- snprintf (config -> web_username , 32 , "admin" );
359+ safe_strcpy (config -> web_username , "admin" , 32 , 0 );
360360 // No default password - will be generated randomly on first run
361361 config -> web_password [0 ] = '\0' ;
362362 config -> webrtc_disabled = false; // WebRTC is enabled by default
@@ -385,7 +385,7 @@ void load_default_config(config_t *config) {
385385 // Memory optimization
386386 config -> buffer_size = 1024 ; // 1024 KB (1 MB) buffer size
387387 config -> use_swap = true;
388- snprintf (config -> swap_file , MAX_PATH_LENGTH , "/var/lib/lightnvr/swap" );
388+ safe_strcpy (config -> swap_file , "/var/lib/lightnvr/swap" , MAX_PATH_LENGTH , 0 );
389389 config -> swap_size = (uint64_t )128 * 1024 * 1024 ; // 128MB swap
390390
391391 // Hardware acceleration
@@ -399,14 +399,14 @@ void load_default_config(config_t *config) {
399399 // CMake passes these as string literals already (e.g. -DGO2RTC_BINARY_PATH_RAW="/usr/local/bin/go2rtc"),
400400 // so they must be used directly — NOT through STRINGIFY, which would double-quote the value.
401401#ifdef GO2RTC_BINARY_PATH_RAW
402- snprintf (config -> go2rtc_binary_path , MAX_PATH_LENGTH , "%s" , GO2RTC_BINARY_PATH_RAW );
402+ safe_strcpy (config -> go2rtc_binary_path , GO2RTC_BINARY_PATH_RAW , MAX_PATH_LENGTH , 0 );
403403#else
404- snprintf (config -> go2rtc_binary_path , MAX_PATH_LENGTH , "/usr/local/bin/go2rtc" );
404+ safe_strcpy (config -> go2rtc_binary_path , "/usr/local/bin/go2rtc" , MAX_PATH_LENGTH , 0 );
405405#endif
406406#ifdef GO2RTC_CONFIG_DIR_RAW
407- snprintf (config -> go2rtc_config_dir , MAX_PATH_LENGTH , "%s" , GO2RTC_CONFIG_DIR_RAW );
407+ safe_strcpy (config -> go2rtc_config_dir , GO2RTC_CONFIG_DIR_RAW , MAX_PATH_LENGTH , 0 );
408408#else
409- snprintf (config -> go2rtc_config_dir , MAX_PATH_LENGTH , "/etc/lightnvr/go2rtc" );
409+ safe_strcpy (config -> go2rtc_config_dir , "/etc/lightnvr/go2rtc" , MAX_PATH_LENGTH , 0 );
410410#endif
411411 config -> go2rtc_api_port = 1984 ;
412412 config -> go2rtc_rtsp_port = 8554 ; // Default RTSP listen port
@@ -417,7 +417,7 @@ void load_default_config(config_t *config) {
417417 config -> go2rtc_webrtc_enabled = true; // Enable WebRTC by default
418418 config -> go2rtc_webrtc_listen_port = 8555 ; // Default WebRTC listen port
419419 config -> go2rtc_stun_enabled = true; // Enable STUN by default for NAT traversal
420- snprintf (config -> go2rtc_stun_server , sizeof ( config -> go2rtc_stun_server ), "stun.l.google.com:19302" );
420+ safe_strcpy (config -> go2rtc_stun_server , "stun.l.google.com:19302" , sizeof ( config -> go2rtc_stun_server ), 0 );
421421 config -> go2rtc_external_ip [0 ] = '\0' ; // Empty by default (auto-detect)
422422 config -> go2rtc_ice_servers [0 ] = '\0' ; // Empty by default (use STUN server)
423423
@@ -430,7 +430,7 @@ void load_default_config(config_t *config) {
430430 // ONVIF discovery settings
431431 config -> onvif_discovery_enabled = false; // Disabled by default
432432 config -> onvif_discovery_interval = 300 ; // 5 minutes between scans
433- snprintf (config -> onvif_discovery_network , sizeof (config -> onvif_discovery_network ), "auto" );
433+ safe_strcpy (config -> onvif_discovery_network , "auto" , sizeof (config -> onvif_discovery_network ), 0 );
434434
435435 // Initialize default values for detection-based recording in streams
436436 for (int i = 0 ; i < config -> max_streams ; i ++ ) {
@@ -458,16 +458,16 @@ void load_default_config(config_t *config) {
458458 config -> mqtt_broker_port = 1883 ; // Default MQTT port
459459 config -> mqtt_username [0 ] = '\0' ; // Optional
460460 config -> mqtt_password [0 ] = '\0' ; // Optional
461- snprintf (config -> mqtt_client_id , sizeof (config -> mqtt_client_id ), "lightnvr" );
462- snprintf (config -> mqtt_topic_prefix , sizeof (config -> mqtt_topic_prefix ), "lightnvr" );
461+ safe_strcpy (config -> mqtt_client_id , "lightnvr" , sizeof (config -> mqtt_client_id ), 0 );
462+ safe_strcpy (config -> mqtt_topic_prefix , "lightnvr" , sizeof (config -> mqtt_topic_prefix ), 0 );
463463 config -> mqtt_tls_enabled = false; // No TLS by default
464464 config -> mqtt_keepalive = 60 ; // 60 seconds keepalive
465465 config -> mqtt_qos = 1 ; // QoS 1 (at least once)
466466 config -> mqtt_retain = false; // Don't retain messages by default
467467
468468 // Home Assistant MQTT auto-discovery settings
469469 config -> mqtt_ha_discovery = false; // Disabled by default
470- snprintf (config -> mqtt_ha_discovery_prefix , sizeof (config -> mqtt_ha_discovery_prefix ), "homeassistant" );
470+ safe_strcpy (config -> mqtt_ha_discovery_prefix , "homeassistant" , sizeof (config -> mqtt_ha_discovery_prefix ), 0 );
471471 config -> mqtt_ha_snapshot_interval = 30 ; // 30 seconds default
472472}
473473
@@ -1288,7 +1288,7 @@ int load_config(config_t *config) {
12881288 // Set default web root if not specified
12891289 if (strlen (config -> web_root ) == 0 ) {
12901290 // Set a default web root path
1291- snprintf (config -> web_root , sizeof (config -> web_root ), "%s" , "/var/www/lightnvr" ); // or another appropriate default
1291+ safe_strcpy (config -> web_root , "/var/www/lightnvr" , sizeof (config -> web_root ), 0 ); // or another appropriate default
12921292 }
12931293
12941294 // Add logging to debug
0 commit comments