pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/security/zoneminder zoneminder: avoid %ld for time_t (...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/b6e23b94c4db
branches:  trunk
changeset: 382736:b6e23b94c4db
user:      gdt <gdt%pkgsrc.org@localhost>
date:      Fri Jul 13 02:05:11 2018 +0000

description:
zoneminder: avoid %ld for time_t (int64_t, not long on arm)

zoneinder uses %ld to print tv.tv_sec, which is of type time_t.  On
NetBSD, that's int64_t, which happens to match long on amd64, but not
on arm, and hence printf often segfaults.  Kludge around this by
casting to long, which should work for about 20 years, by which time a
proper fix should have arrived in a zoneminder release.

Not yet raised upstream, because our package is 1.28.1 and upstream
has released 1.30.4.

diffstat:

 security/zoneminder/Makefile                              |   5 +-
 security/zoneminder/distinfo                              |   7 +-
 security/zoneminder/patches/patch-src_zm__event.cpp       |  57 +++++++++++++++
 security/zoneminder/patches/patch-src_zm__rtp__source.cpp |  24 ++++++
 security/zoneminder/patches/patch-src_zm_logger_cpp       |  17 +++-
 security/zoneminder/patches/patch-src_zmu.cpp             |  31 ++++++++
 6 files changed, 133 insertions(+), 8 deletions(-)

diffs (219 lines):

diff -r 2f10ca0ffa66 -r b6e23b94c4db security/zoneminder/Makefile
--- a/security/zoneminder/Makefile      Fri Jul 13 00:56:48 2018 +0000
+++ b/security/zoneminder/Makefile      Fri Jul 13 02:05:11 2018 +0000
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.37 2018/03/12 11:17:31 wiz Exp $
+# $NetBSD: Makefile,v 1.38 2018/07/13 02:05:11 gdt Exp $
 
 PKGNAME=       ${DISTNAME:S/ZoneMinder-/zoneminder-/}
 DISTNAME=      ZoneMinder-1.28.1
-PKGREVISION=   15
+PKGREVISION=   16
 CATEGORIES=    security
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=ZoneMinder/}
 GITHUB_PROJECT=        ZoneMinder
@@ -127,6 +127,7 @@
 DEPENDS+=      ${PHP_PKG_PREFIX}-pdo_mysql-[0-9]*:../../databases/php-pdo_mysql
 .endif
 
+# \todo Somehow, this permission setup still fails.
 # This directory contains state, so use OWN_DIRS instead of MAKE_DIRS.
 ZM_CACHE=      ${VARBASE}/cache/zoneminder
 OWN_DIRS_PERMS+=       ${ZM_CACHE} ${REAL_ROOT_USER} ${REAL_ROOT_GROUP} 755
diff -r 2f10ca0ffa66 -r b6e23b94c4db security/zoneminder/distinfo
--- a/security/zoneminder/distinfo      Fri Jul 13 00:56:48 2018 +0000
+++ b/security/zoneminder/distinfo      Fri Jul 13 02:05:11 2018 +0000
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.10 2017/09/09 07:55:31 alnsn Exp $
+$NetBSD: distinfo,v 1.11 2018/07/13 02:05:11 gdt Exp $
 
 SHA1 (ZoneMinder-1.28.1.tar.gz) = 3e173ae1aac529b60d79a5fc668c107f0679d0a2
 RMD160 (ZoneMinder-1.28.1.tar.gz) = b3cc305656cb5b73d4ac0e21fe937c237467cdd1
@@ -9,7 +9,9 @@
 SHA1 (patch-scripts_ZoneMinder_lib_ZoneMinder_General_pm) = 841d897662958698a4dfcb95dd5bc43bb5fed568
 SHA1 (patch-scripts_zm_in) = 8f59085bb9293afa7aeb268000c75988e5371c66
 SHA1 (patch-src_Makefile_am) = 0f6571c9d5a3e688544f93d687d266e1b71f0f43
+SHA1 (patch-src_zm__event.cpp) = 2db5a2f85039e711ab6a18af816e0269611fc5f2
 SHA1 (patch-src_zm__monitor.cpp) = dcc3816686a6a7c375d4716d3663b4c922c90439
+SHA1 (patch-src_zm__rtp__source.cpp) = eecca36c18a6611745c49686499a16df177abc7f
 SHA1 (patch-src_zm__sdp.cpp) = ed89bc14ae557281bb43baca9c90b78d801d8eb1
 SHA1 (patch-src_zm__thread.h) = 67dbd1e9c19df63fd120344cc8a36d663a724409
 SHA1 (patch-src_zm__timer.h) = 38080d08b5834e3dae713e81488944887ce5848b
@@ -18,11 +20,12 @@
 SHA1 (patch-src_zm_comms_cpp) = d40932a3d0ae4375a649f200d973995d56aa71c7
 SHA1 (patch-src_zm_comms_h) = baeb73040ff3ba862f23ad6301de7daba182456e
 SHA1 (patch-src_zm_ffmpeg_camera_cpp) = 6ead5f9afbe984aab14fee337093fd0269c6e9d8
-SHA1 (patch-src_zm_logger_cpp) = 3b0373e9d648d25ef4e3e09429199f654f876ccb
+SHA1 (patch-src_zm_logger_cpp) = 6e0124756ef6fe58fb452651337d622ddff6c4ab
 SHA1 (patch-src_zm_remote_camera_h) = 0d4bd7dae0188df7e463586250ac2ed530230f3d
 SHA1 (patch-src_zm_signal_cpp) = fa11938f55ccd50a1a9e949d6b58dd07773f2690
 SHA1 (patch-src_zm_thread_cpp) = c5f64697c3024c6c382f9ae2c5dbe9c21b529b6e
 SHA1 (patch-src_zmc_cpp) = d1046ddfad3a88bdd30501237834ec9e9fbc4c83
 SHA1 (patch-src_zmf.cpp) = a059b9ae068037c6f68c16dab861ed830dd1c7e2
+SHA1 (patch-src_zmu.cpp) = a95e81285167fc8df77bc059c7b7f09cc36ff922
 SHA1 (patch-web_Makefile.am) = ddb3815fa1b1799658034789302c8d3840f2b894
 SHA1 (patch-web_ajax_stream_php) = e8f811e63bedec03345b74db72c3d8014b3cc7f6
diff -r 2f10ca0ffa66 -r b6e23b94c4db security/zoneminder/patches/patch-src_zm__event.cpp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/security/zoneminder/patches/patch-src_zm__event.cpp       Fri Jul 13 02:05:11 2018 +0000
@@ -0,0 +1,57 @@
+$NetBSD: patch-src_zm__event.cpp,v 1.1 2018/07/13 02:05:11 gdt Exp $
+
+zoneminder uses %ld for time_t, which is troublesome on NetBSD mrm and
+presumably i386.  (Note that there are multiple patch files for the
+same issue.)
+
+Not yet sent upstream -- needs update to latest release first, where
+it might be fixed, or the patch might simply need to be rebased.
+Also, this fix is expedient and probably a better fix is appropriate.
+
+--- src/zm_event.cpp.orig      2015-02-05 02:52:37.000000000 +0000
++++ src/zm_event.cpp
+@@ -74,7 +74,7 @@ Event::Event( Monitor *p_monitor, struct
+     static char sql[ZM_SQL_MED_BUFSIZ];
+ 
+     struct tm *stime = localtime( &start_time.tv_sec );
+-    snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes ) values ( %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s' )", monitor->Id(), 
start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str() );
++    snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes ) values ( %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s' )", monitor->Id(), 
(long) start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str() );
+     if ( mysql_query( &dbconn, sql ) )
+     {
+         Error( "Can't insert event: %s", mysql_error( &dbconn ) );
+@@ -172,7 +172,7 @@ Event::~Event()
+ 
+         Debug( 1, "Adding closing frame %d to DB", frames );
+         static char sql[ZM_SQL_SML_BUFSIZ];
+-        snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, TimeStamp, Delta ) values ( %d, %d, from_unixtime( %ld ), %s%ld.%02ld )", id, frames, end_time.tv_sec, 
delta_time.positive?"":"-", delta_time.sec, delta_time.fsec );
++        snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, TimeStamp, Delta ) values ( %d, %d, from_unixtime( %ld ), %s%ld.%02ld )", id, frames, (long) end_time.tv_sec, 
delta_time.positive?"":"-", delta_time.sec, delta_time.fsec );
+         if ( mysql_query( &dbconn, sql ) )
+         {
+             Error( "Can't insert frame: %s", mysql_error( &dbconn ) );
+@@ -185,7 +185,7 @@ Event::~Event()
+     struct DeltaTimeval delta_time;
+     DELTA_TIMEVAL( delta_time, end_time, start_time, DT_PREC_2 );
+ 
+-    snprintf( sql, sizeof(sql), "update Events set Name='%s%d', EndTime = from_unixtime( %ld ), Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d 
where Id = %d", monitor->EventPrefix(), id, end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, frames, alarm_frames, tot_score, 
(int)(alarm_frames?(tot_score/alarm_frames):0), max_score, id );
++    snprintf( sql, sizeof(sql), "update Events set Name='%s%d', EndTime = from_unixtime( %ld ), Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d 
where Id = %d", monitor->EventPrefix(), id, (long) end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, frames, alarm_frames, tot_score, 
(int)(alarm_frames?(tot_score/alarm_frames):0), max_score, id );
+     if ( mysql_query( &dbconn, sql ) )
+     {
+         Error( "Can't update event: %s", mysql_error( &dbconn ) );
+@@ -520,7 +520,7 @@ void Event::AddFramesInternal( int n_fra
+         DELTA_TIMEVAL( delta_time, *(timestamps[i]), start_time, DT_PREC_2 );
+ 
+         int sql_len = strlen(sql);
+-        snprintf( sql+sql_len, sizeof(sql)-sql_len, "( %d, %d, from_unixtime(%ld), %s%ld.%02ld ), ", id, frames, timestamps[i]->tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec );
++        snprintf( sql+sql_len, sizeof(sql)-sql_len, "( %d, %d, from_unixtime(%ld), %s%ld.%02ld ), ", id, frames, (long) timestamps[i]->tv_sec, delta_time.positive?"":"-", delta_time.sec, 
delta_time.fsec );
+ 
+         frameCount++;
+     }
+@@ -569,7 +569,7 @@ void Event::AddFrame( Image *image, stru
+ 
+         Debug( 1, "Adding frame %d to DB", frames );
+         static char sql[ZM_SQL_MED_BUFSIZ];
+-        snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %d, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type, 
timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score );
++        snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %d, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type, 
(long) timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score );
+         if ( mysql_query( &dbconn, sql ) )
+         {
+             Error( "Can't insert frame: %s", mysql_error( &dbconn ) );
diff -r 2f10ca0ffa66 -r b6e23b94c4db security/zoneminder/patches/patch-src_zm__rtp__source.cpp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/security/zoneminder/patches/patch-src_zm__rtp__source.cpp Fri Jul 13 02:05:11 2018 +0000
@@ -0,0 +1,24 @@
+$NetBSD: patch-src_zm__rtp__source.cpp,v 1.1 2018/07/13 02:05:11 gdt Exp $
+
+--- src/zm_rtp_source.cpp.orig 2015-02-05 02:52:37.000000000 +0000
++++ src/zm_rtp_source.cpp
+@@ -197,7 +197,7 @@ void RtpSource::updateRtcpData( uint32_t
+ {
+     struct timeval ntpTime = tvMake( ntpTimeSecs, suseconds_t((USEC_PER_SEC*(ntpTimeFrac>>16))/(1<<16)) );
+ 
+-    Debug( 5, "ntpTime: %ld.%06ld, rtpTime: %x", ntpTime.tv_sec, ntpTime.tv_usec, rtpTime );
++    Debug( 5, "ntpTime: %ld.%06ld, rtpTime: %x", (long) ntpTime.tv_sec, ntpTime.tv_usec, rtpTime );
+                                                      
+     if ( mBaseTimeNtp.tv_sec == 0 )
+     {
+@@ -207,8 +207,8 @@ void RtpSource::updateRtcpData( uint32_t
+     }
+     else if ( !mRtpClock )
+     {
+-        Debug( 5, "lastSrNtpTime: %ld.%06ld, rtpTime: %x", mLastSrTimeNtp.tv_sec, mLastSrTimeNtp.tv_usec, rtpTime );
+-        Debug( 5, "ntpTime: %ld.%06ld, rtpTime: %x", ntpTime.tv_sec, ntpTime.tv_usec, rtpTime );
++      Debug( 5, "lastSrNtpTime: %ld.%06ld, rtpTime: %x", (long) mLastSrTimeNtp.tv_sec, mLastSrTimeNtp.tv_usec, rtpTime );
++        Debug( 5, "ntpTime: %ld.%06ld, rtpTime: %x", (long) ntpTime.tv_sec, ntpTime.tv_usec, rtpTime );
+ 
+         double diffNtpTime = tvDiffSec( mBaseTimeNtp, ntpTime );
+         uint32_t diffRtpTime = rtpTime - mBaseTimeRtp;
diff -r 2f10ca0ffa66 -r b6e23b94c4db security/zoneminder/patches/patch-src_zm_logger_cpp
--- a/security/zoneminder/patches/patch-src_zm_logger_cpp       Fri Jul 13 00:56:48 2018 +0000
+++ b/security/zoneminder/patches/patch-src_zm_logger_cpp       Fri Jul 13 02:05:11 2018 +0000
@@ -1,11 +1,11 @@
-$NetBSD: patch-src_zm_logger_cpp,v 1.3 2013/04/29 21:31:13 joerg Exp $
+$NetBSD: patch-src_zm_logger_cpp,v 1.4 2018/07/13 02:05:11 gdt Exp $
 
 If the system has syscall() but not SYS_gettid [E.g. NetBSD], don't attempt
 to use SYS_gettid.
 
---- src/zm_logger.cpp.orig     2011-06-28 11:07:35.000000000 +0000
+--- src/zm_logger.cpp.orig     2015-02-05 02:52:37.000000000 +0000
 +++ src/zm_logger.cpp
-@@ -33,6 +33,7 @@
+@@ -31,6 +31,7 @@
  #include <signal.h>
  #include <stdarg.h>
  #include <errno.h>
@@ -13,7 +13,7 @@
  
  bool Logger::smInitialised = false;
  Logger *Logger::smInstance = 0;
-@@ -515,7 +516,7 @@ void Logger::logPrint( bool hex, const c
+@@ -527,7 +528,7 @@ void Logger::logPrint( bool hex, const c
      #endif
  
          pid_t tid;
@@ -22,3 +22,12 @@
          if ( (tid = syscall(SYS_gettid)) < 0 ) // Thread/Process id
  #endif // HAVE_SYSCALL
          tid = getpid(); // Process id
+@@ -581,7 +582,7 @@ void Logger::logPrint( bool hex, const c
+             char escapedString[(strlen(syslogStart)*2)+1];
+ 
+             mysql_real_escape_string( &mDbConnection, escapedString, syslogStart, strlen(syslogStart) );
+-            snprintf( sql, sizeof(sql), "insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( %ld.%06ld, '%s', %d, %d, '%s', '%s', '%s', %d )", timeVal.tv_sec, 
timeVal.tv_usec, mId.c_str(), tid, level, classString, escapedString, file, line );
++            snprintf( sql, sizeof(sql), "insert into Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) values ( %ld.%06ld, '%s', %d, %d, '%s', '%s', '%s', %d )", (long) 
timeVal.tv_sec, timeVal.tv_usec, mId.c_str(), tid, level, classString, escapedString, file, line );
+             if ( mysql_query( &mDbConnection, sql ) )
+             {
+                 databaseLevel( NOLOG );
diff -r 2f10ca0ffa66 -r b6e23b94c4db security/zoneminder/patches/patch-src_zmu.cpp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/security/zoneminder/patches/patch-src_zmu.cpp     Fri Jul 13 02:05:11 2018 +0000
@@ -0,0 +1,31 @@
+$NetBSD: patch-src_zmu.cpp,v 1.1 2018/07/13 02:05:11 gdt Exp $
+
+--- src/zmu.cpp.orig   2015-02-05 02:52:37.000000000 +0000
++++ src/zmu.cpp
+@@ -457,7 +457,7 @@ int main( int argc, char *argv[] )
+                               else
+                               {
+                                       if ( have_output ) printf( "%c", separator );
+-                                      printf( "%ld.%02ld", timestamp.tv_sec, timestamp.tv_usec/10000 );
++                                      printf( "%ld.%02ld", (long) timestamp.tv_sec, timestamp.tv_usec/10000 );
+                                       have_output = true;
+                               }
+                       }
+@@ -729,7 +729,7 @@ int main( int argc, char *argv[] )
+                                                               function,
+                                                               monitor->GetState(),
+                                                               monitor->GetTriggerState(),
+-                                                              tv.tv_sec, tv.tv_usec/10000,
++                                                              (long) tv.tv_sec, tv.tv_usec/10000,
+                                                               monitor->GetLastReadIndex(),
+                                                               monitor->GetLastWriteIndex(),
+                                                               monitor->GetLastEvent(),
+@@ -746,7 +746,7 @@ int main( int argc, char *argv[] )
+                                                       function,
+                                                       0,
+                                                       0,
+-                                                      tv.tv_sec, tv.tv_usec/10000,
++                                                      (long) tv.tv_sec, tv.tv_usec/10000,
+                                                       0,
+                                                       0,
+                                                       0,



Home | Main Index | Thread Index | Old Index