A Remote monitor on the HTTP protocol logs every request it sends to the
camera at debug level 2: with a user and password that includes
"Authorization: Basic <base64 of user:password>", and the path's query
string, which for many cameras carries user= and pwd=. When the camera
asks for Digest, Authenticator::computeDigestResponse() logged
"<user>:<realm>:<password>" in clear and the HA1 hash, which is all a
client needs to answer that realm's challenges.
Add request_for_log(), which passes the request target through
url_for_log() and replaces the value of Authorization and
Proxy-Authorization headers, and log the requests through it. Drop the
two Digest lines that held the password and HA1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RemoteCameraHttp read the camera's Content-Length with atoi() and then asked
ReadData() for that many bytes, which passes the count straight to
Buffer::read_into(). Buffer::expand() worked in int: once the allocation passed
INT_MAX the spare space went negative, it grew again, and mAllocation + count
wrapped to a small value, so the following memcpy or read() wrote the camera's
data past a small heap block. Whoever answers the camera's HTTP request, often
on a plain-HTTP link, could crash zmc in a loop or corrupt its heap.
- RemoteCameraHttp::ParseContentLength() replaces the four atoi() calls. It
refuses a length that is not a number or is larger than twice the monitor's
raw frame size plus one network buffer (capped at 1 GiB), and GetResponse()
fails the response instead of buffering it.
- Buffer::expand() does its arithmetic in size_t, grows to exactly what is
needed, and refuses to hold more than INT_MAX bytes, since read_into()
returns the count as an int.
- Buffer::read_into() refuses a read that does not fit after expand() rather
than reading past the allocation.
tests/zm_buffer.cpp covers reads through a pipe, an oversized read, data kept
across a shift and a grow, and the Content-Length bounds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RemoteCameraHTTP::GetResponse()'s non-PCRE parser (the default when built
without PCRE) copied server-controlled HTTP response header values into
fixed-size static buffers with unbounded strcpy()/sprintf(), and with
strncpy() bounds derived from delimiters rather than the buffer size. A
malicious or MitM'd HTTP camera could overflow status_mesg[256],
connection_type[32], content_type[32] and content_boundary[64],
corrupting adjacent parser state (content_length, content_boundary_len)
for DoS and secondary heap corruption.
Add zm_strncpy(): a bounded copy that always null-terminates (strcpy
overflows; strncpy skips the terminator on truncation) and optionally
caps to a field length n for delimiter-bounded values whose source is
not null-terminated at the field end. Route every header copy in
GetResponse() through it. The content_boundary "--" prefix is written
separately and content_boundary_len is taken from strlen() of the
resulting (now bounded) string so the compare length at the multipart
subheader match stays correct.
The two subcontent-header strncpy() calls were already bounded to
sizeof-1 with an explicit terminator and are left as-is.
Adds a tests/zm_utils.cpp self-check covering fit, truncation,
delimiter-limit, delimiter-over-buffer, and empty-source cases.
Refs GHSA-93j4-rcp9-9jx6.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Buffer was sized for binary in6_addr (16 bytes) but inet_ntop needs
space for string representation (INET6_ADDRSTRLEN = 46 bytes).
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
getsockopt() returns -1 on error, not an errno value. The actual error
code is stored in errno. Using strerror(retval) with retval=-1 gives
incorrect error messages.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove all uses of deprecated av_init_packet() and switch any stack
based AVPackets to unique_ptrs allocated with av_packet_alloc().
Ensure that all code paths call av_packet_unref() after use to reset
before next usage.
Follow-up to 814953b331
It turns out [[gcc::fallthrough]] and -Wimplicit-fallthrough were only implemented in GCC 7 and throws a warning on older GCCs.
Add the FALLTHROUGH macro to handle GCC < 7 as found on Xenial.
Warning from GCC 5.5:
/home/runner/work/zoneminder/zoneminder/src/zm_remote_camera_http.cpp:624:13: warning: attributes at the beginning of statement are ignored [-Wattributes]
[[gnu::fallthrough]];
Also remove Camera::getId() which returend the monitor ID. Since a camera is owned by an monitor, there is no need for this. Also it causes a circular include.
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