From 509de3ec270f38732d6a1af122983b558d147f41 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 13 Jan 2015 15:16:38 -0500 Subject: [PATCH 1/2] need to cast malloc, get rid of perl code, only swap_path checks if we are going to use it --- src/zm_monitor.cpp | 58 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 07194d284..a20c0c4f0 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -3940,38 +3940,38 @@ void MonitorStream::runStream() temp_read_index = temp_image_buffer_count; temp_write_index = temp_image_buffer_count; - char swap_path[PATH_MAX] = ""; + char *swap_path; bool buffered_playback = false; + int swap_path_length = strlen(config.path_swap)+1; // +1 for NULL terminator - if ( connkey && playback_buffer > 0 ) - { - Debug( 2, "Checking swap image location" ); - Debug( 3, "Checking swap image path" ); - strncpy( swap_path, config.path_swap, sizeof(swap_path) ); - if ( checkSwapPath( swap_path, false ) ) - { - snprintf( &(swap_path[strlen(swap_path)]), sizeof(swap_path)-strlen(swap_path), "/zmswap-m%d", monitor->Id() ); - if ( checkSwapPath( swap_path, true ) ) - { - snprintf( &(swap_path[strlen(swap_path)]), sizeof(swap_path)-strlen(swap_path), "/zmswap-q%06d", connkey ); - if ( checkSwapPath( swap_path, true ) ) - { - buffered_playback = true; - } - } - } + if ( connkey && playback_buffer > 0 ) { - if ( !buffered_playback ) - { - Error( "Unable to validate swap image path, disabling buffered playback" ); - } - else - { - Debug( 2, "Assigning temporary buffer" ); - temp_image_buffer = new SwapImage[temp_image_buffer_count]; - memset( temp_image_buffer, 0, sizeof(*temp_image_buffer)*temp_image_buffer_count ); - Debug( 2, "Assigned temporary buffer" ); - } + if ( swap_path_length + 15 > PATH_MAX ) { + // 15 is for /zmswap-whatever, assuming max 6 digits for monitor id + Error( "Swap Path is too long. %d > %d ", swap_path_length+15, PATH_MAX ); + } else { + swap_path = (char *)malloc( swap_path_length+15 ); + Debug( 3, "Checking swap image path %s", config.path_swap ); + strncpy( swap_path, config.path_swap, swap_path_length ); + if ( checkSwapPath( swap_path, false ) ) { + snprintf( &(swap_path[swap_path_length]), sizeof(swap_path)-swap_path_length, "/zmswap-m%d", monitor->Id() ); + if ( checkSwapPath( swap_path, true ) ) { + snprintf( &(swap_path[swap_path_length]), sizeof(swap_path)-swap_path_length, "/zmswap-q%06d", connkey ); + if ( checkSwapPath( swap_path, true ) ) { + buffered_playback = true; + } + } + } + + if ( !buffered_playback ) { + Error( "Unable to validate swap image path, disabling buffered playback" ); + } else { + Debug( 2, "Assigning temporary buffer" ); + temp_image_buffer = new SwapImage[temp_image_buffer_count]; + memset( temp_image_buffer, 0, sizeof(*temp_image_buffer)*temp_image_buffer_count ); + Debug( 2, "Assigned temporary buffer" ); + } + } } float max_secs_since_last_sent_frame = 10.0; //should be > keep alive amount (5 secs) From facda38871cf364c3388d28c1640d39d5e37fd34 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 13 Jan 2015 19:52:15 -0500 Subject: [PATCH 2/2] add corresponding free --- src/zm_monitor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index a20c0c4f0..71befb769 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -3940,7 +3940,7 @@ void MonitorStream::runStream() temp_read_index = temp_image_buffer_count; temp_write_index = temp_image_buffer_count; - char *swap_path; + char *swap_path = 0; bool buffered_playback = false; int swap_path_length = strlen(config.path_swap)+1; // +1 for NULL terminator @@ -4209,6 +4209,7 @@ void MonitorStream::runStream() } } } + if ( swap_path ) free( swap_path ); closeComms(); }