Commit Graph
37 Commits
Author SHA1 Message Date
SteveGilvarryandClaude Fable 5 06ebedad4a fix: repair latent zm::comms bugs exposed by first TcpUnixServer use
StreamSocket (next commit) is the first in-tree code to instantiate
zm::TcpUnixServer and zm::Pipe; three pre-existing defects surfaced:

- TcpUnixServer::listen() and accept() were declared but never defined,
  failing at link time for any user of the class
- TcpUnixSocket/TcpInetSocket's (socket, newSd) constructors delegated to
  TcpSocket only; Socket is a virtual base, so the descriptor-carrying
  constructor was ignored and accepted sockets ended up with mSd == -1
  (writes failed with EBADF)
- Pipe::setBlocking() only changed the write end; reads on the
  supposedly non-blocking pipe blocked forever

Tests: covered indirectly by the StreamSocket suite added in the next
commit; full ctest suite (98 tests) passes at the branch head.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-16 05:00:44 +10:00
Steve GilvarryandClaude Opus 4.8 9b96bcee9f fix: set SO_REUSEADDR before bind in InetSocket::bind refs #4998
InetSocket::bind creates its socket inside the getaddrinfo loop and
called ::bind without SO_REUSEADDR, so a connection lingering in
TIME_WAIT on the same port fails the bind with EADDRINUSE. Seen as
zm_comms test failures on macOS when the send/recv test runs before
the server bind tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-12 15:19:25 +10:00
Isaac ConnorandClaude Opus 4.5 df6c4a4a13 fix: address multiple bugs across core source files
- zm_analysis_thread.cpp, zm_decoder_thread.cpp: Fix potential deadlock
  in Start() by calling Stop() before joining thread
- zm_camera.cpp: Add null check after avformat_alloc_context()
- zm_comms.cpp: Fix memory leak in InetSocket::bind(), fix error message
  typo in deleteReader(), fix clearReaders/clearWriters to recalculate
  mMaxFd properly
- zm_config.cpp: Fix potential buffer underrun when parsing config files,
  fix misplaced SERVER_ID check logic
- zm_db.cpp: Fix logger level not restored on early return in zmDbDo(),
  fix empty string access in DB_HOST parsing
- zm_event.cpp: Fix typo "foudn" -> "found", fix memory leak with Tag
  allocation, fix variable shadowing with video_file
- zm_event_tag.cpp: Fix null dereference when AssignedBy is NULL
- zm_eventstream.cpp: Fix dangling pointer bugs with emplace_back
  (use auto& instead of auto), fix memory leak in loadInitialEventData

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 10:18:49 -05:00
Isaac ConnorandClaude Opus 4.5 c9ab9815e6 fix: correct two bugs in socket/select handling
1. Socket::getBlocking() returned inverted logic. When O_NONBLOCK flag
   is set, the socket is non-blocking, so blocking should be false.
   The code returned true when O_NONBLOCK was set.

2. Select::wait() checked the wrong fd_set for writers. It checked
   &rfds (read fd_set) instead of &wfds (write fd_set), meaning
   writeable sockets were never properly detected.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 20:42:21 -05:00
Peter Keresztes Schmidt 3e8b10d813 zm::Select: Convert API to std::chrono 2021-06-13 23:22:51 +02:00
Peter Keresztes Schmidt 46155942c1 Misc: Rename namespace ZM to zm
We had a mixture of both spellings. Unify it according to our code-style.
2021-06-06 19:11:11 +02:00
Peter Keresztes Schmidt e5cac38521 Comms: Make sure sun_path is NUL-terminated
When using strncpy the NUL-termination can go missing if the string to be copied is longer than the buffer.
Make sure the last character in the buffer is NUL.
If this really happens, the error (non-existing path due to truncation) will be caught during bind-ing.

Fixes the following warning:
/home/peterke/DEV/zoneminder/src/zm_comms.cpp: In member function ‘bool ZM::SockAddrUnix::resolve(const char*, const char*)’:
/home/peterke/DEV/zoneminder/src/zm_comms.cpp:207:10: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 108 equals destination size [-Wstringop-truncation]
  207 |   strncpy(mAddrUn.sun_path, path, sizeof(mAddrUn.sun_path));
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-05-24 00:44:15 +02:00
Peter Keresztes Schmidt 298415fff3 Remove remaining usages of VLAs 2021-05-17 22:12:04 +02:00
Isaac Connor ece981c018 Fix bool return value when int is desired 2021-04-20 10:41:41 -04:00
Peter Keresztes Schmidt 3d2614b429 comms: Quick-fix a crash in ZM::Socket::Accept
mLocalAddr is always nullptr and not used anywhere. So just use a local variable for
the time being.
The comms types will need an API rework since the current one is rather convoluted.
Postpone fixing this properly until then.
2021-04-11 01:28:23 +02:00
Peter Keresztes Schmidt 7dee86b104 comms: auto-format 2021-04-11 00:23:17 +02:00
Peter Keresztes Schmidt 4056782954 Comms: Move all classes to ZM:: namespace
The Socket class collides with a class named the same way from liblive555. This confuses the linker and links the wrong object leading to a crash when connecting to the RTSP server.
2021-02-09 14:45:33 +01:00
Peter Keresztes Schmidt 0dbc39ee25 Cleanup and reorganize includes
With this commit a unified structure for includes is introduced.
The general rules:
 * Only include what you need
 * Include wherever possible in the cpp and forward-declare in the header

 The includes are sorted in a local to global fashion. This means for the include order:
  0. If cpp file: The corresponding h file and an empty line
  1. Includes from the project sorted alphabetically
  2. System/library includes sorted alphabetically
  3. Conditional includes
2021-02-04 18:02:01 +01:00
Peter Keresztes Schmidt 5a57efdfe2 Replace deprecated C header includes with the C++ ones. 2021-02-04 05:39:03 +01:00
Isaac Connor 5f4fb4200f googe code style 2020-11-21 09:25:10 -05:00
Peter Keresztes Schmidt 8f980a1168 Convert NULL/0 to nullptr
The 0 -> nullptr changes should definitely improve readability.
2020-08-26 22:03:40 +02:00
Isaac Connor 49be06d641 move freeaddrinfo up before a return to prevent memleak 2017-12-12 12:35:05 -05:00
Isaac Connor 64816aa005 fixes from cppcheck. 2017-11-18 16:00:10 -05:00
Isaac Connor 22ff831859 more cppcheck recommendations 2017-11-16 21:21:56 -05:00
Andy Bauer 254fcbcef7 update gpl 2 mailing address in source files 2016-12-26 09:23:16 -06:00
Isaac Connor fd896acd50 Merge branch 'RTSP-IPv6' of https://github.com/schrorg/ZoneMinder into schrorg-RTSP-IPv6 2016-05-06 08:32:21 -04:00
Isaac Connor 03b1ced568 tabs to spaces and use 2space indenting 2016-04-04 10:11:48 -04:00
Robin Daermann 4c773472bd Add support for IPv6 in RTSP code
Monitors with source type 'remote' can now be accessed over IPv6. This
code uses getaddrinfo(3) now instead of gethostbyname(3) - and changes a
lot of networking stuff which should be tested thoroughly.
2015-11-04 16:41:47 +01:00
Rick Sayre 12516da3dc Patched in changes to 1.28.1 to allow OmniOS/Illumos to build and work
haven't attempted to build yet, there are some changes
2015-05-17 17:18:54 -07:00
Isaac Connor 14c65aefd2 Merge branch 'master' of github.com:ZoneMinder/ZoneMinder
Conflicts:
	src/zm_comms.cpp
2015-01-03 13:56:40 -05:00
Isaac Connor e02da8833a ifdef's for BSD 2015-01-02 17:08:51 -05:00
Isaac Connor 92e6d940bc ifdef's for BSD and cleanup 2015-01-02 17:07:49 -05:00
Isaac Connor 1137c3907e ifdef's for BSD 2015-01-02 17:06:16 -05:00
Isaac Connor e460c6f448 BSD uses some different includes, these are from FreeBSD ports 2015-01-01 17:18:12 -05:00
stan 6ff385e407 git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@3459 e3e1d417-86f3-4887-817a-d78f3d33393f 2011-06-21 09:19:10 +00:00
stan c0fb4fef7a Fixed multiplier on float version of select timeout.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2652 e3e1d417-86f3-4887-817a-d78f3d33393f
2008-10-09 08:27:10 +00:00
stan e6041e24a7 Uppdated copyright headers
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2611 e3e1d417-86f3-4887-817a-d78f3d33393f
2008-07-25 09:33:23 +00:00
stan aa26ab7b18 git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2532 e3e1d417-86f3-4887-817a-d78f3d33393f 2008-07-16 08:35:59 +00:00
stan ee44d4b274 Updated debug format
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2513 e3e1d417-86f3-4887-817a-d78f3d33393f
2008-07-14 14:43:47 +00:00
stan 235dde1a80 Updated copyright statement.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1829 e3e1d417-86f3-4887-817a-d78f3d33393f
2006-01-17 10:56:30 +00:00
stan 264c23d687 Updated copyright statement
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1360 e3e1d417-86f3-4887-817a-d78f3d33393f
2005-02-24 14:40:14 +00:00
stan a232e7f8b1 Added to CVS for future consideration.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@511 e3e1d417-86f3-4887-817a-d78f3d33393f
2003-04-22 14:16:22 +00:00