From 95087beeb97a01ef38fdca5e1eaf888292e118b4 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 12 Aug 2015 11:00:41 -0400 Subject: [PATCH 1/5] use return value of stat instead of just checking errno. This has the added benefit of catching other errors when stating --- src/zm_event.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 3e723fa48..72df9a1cf 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -119,13 +119,16 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string struct stat statbuf; errno = 0; - stat( path, &statbuf ); - if ( errno == ENOENT || errno == ENOTDIR ) - { - if ( mkdir( path, 0755 ) ) - { - Fatal( "Can't mkdir %s: %s", path, strerror(errno)); - } + if ( stat( path, &statbuf ) ) { + if ( errno == ENOENT || errno == ENOTDIR ) + { + if ( mkdir( path, 0755 ) ) + { + Fatal( "Can't mkdir %s: %s", path, strerror(errno)); + } + } else { + Warning( "Error stat'ing %s, may be fatal. error is %s", path, strerror(errno)); + } } if ( i == 2 ) strncpy( date_path, path, sizeof(date_path) ); From 89e13c1cc0c0e19a16137b16d28c3a6d467e4586 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 14 Aug 2015 16:10:44 -0400 Subject: [PATCH 2/5] leave 1 char at end for \0 --- src/zm_monitor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index c6b8c167d..5822c106f 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -325,10 +325,10 @@ Monitor::Monitor( timestamps( 0 ), images( 0 ) { - strncpy( name, p_name, sizeof(name) ); + strncpy( name, p_name, sizeof(name)-1 ); - strncpy( event_prefix, p_event_prefix, sizeof(event_prefix) ); - strncpy( label_format, p_label_format, sizeof(label_format) ); + strncpy( event_prefix, p_event_prefix, sizeof(event_prefix)-1 ); + strncpy( label_format, p_label_format, sizeof(label_format)-1 ); // Change \n to actual line feeds char *token_ptr = label_format; From b6ee4e422803bc876364e2c63c4e84fd1dbf0703 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 24 Mar 2016 09:43:15 -0400 Subject: [PATCH 3/5] move return up into #ifdef. --- src/zm_rtsp_auth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_rtsp_auth.cpp b/src/zm_rtsp_auth.cpp index 10ecf3475..9521a81d1 100644 --- a/src/zm_rtsp_auth.cpp +++ b/src/zm_rtsp_auth.cpp @@ -201,8 +201,8 @@ std::string Authenticator::computeDigestResponse(std::string &method, std::strin return md5HexBuf; #else // HAVE_DECL_MD5 Error( "You need to build with gnutls or openssl installed to use digest authentication" ); -#endif // HAVE_DECL_MD5 return( 0 ); +#endif // HAVE_DECL_MD5 } void Authenticator::checkAuthResponse(std::string &response) { From 1e52a8ad2c8fcff7512bde9cdab4f55baee57b74 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 24 Mar 2016 09:44:34 -0400 Subject: [PATCH 4/5] remove unused class member --- src/zm_monitor.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 8a9fb34c6..a9cd05674 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -301,9 +301,6 @@ protected: const unsigned char *privacy_bitmask; - - int iDoNativeMotDet; - int n_linked_monitors; MonitorLink **linked_monitors; From a16c1746e52926a44be80552d5f7c89121853ae3 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 24 Mar 2016 10:00:02 -0400 Subject: [PATCH 5/5] separate a failure to open versus failure to lock. Quiets coverity because close can't handle a negative value --- src/zm_stream.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/zm_stream.cpp b/src/zm_stream.cpp index c66638759..77c94e68c 100644 --- a/src/zm_stream.cpp +++ b/src/zm_stream.cpp @@ -294,7 +294,12 @@ void StreamBase::openComms() snprintf( sock_path_lock, sizeof(sock_path_lock), "%s/zms-%06d.lock", config.path_socks, connkey); lock_fd = open(sock_path_lock, O_CREAT|O_WRONLY, S_IRUSR | S_IWUSR); - if (lock_fd <= 0 || flock(lock_fd, LOCK_EX) != 0) + if ( lock_fd <= 0 ) + { + Error("Unable to open sock lock file %s: %s", sock_path_lock, strerror(errno) ); + lock_fd = 0; + } + else if ( flock(lock_fd, LOCK_EX) != 0 ) { Error("Unable to lock sock lock file %s: %s", sock_path_lock, strerror(errno) );