Opened 7 years ago
Closed 7 years ago
Last modified 7 years ago
#13466 closed Bug Report - Crash (fixed)
mythzmserver stdlib assumptions
| Reported by: | dscoular | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 30.1 |
| Component: | Plugin - MythZoneminder | Version: | v30-fixes |
| Severity: | medium | Keywords: | mythzmserver |
| Cc: | Ticket locked: | no |
Description
zmserver.cpp makes assumptions that the row being returned from the zoneminder database has fields which are not NULL. In my case, my zoneminder database has cameras where there is no "host" defined because they are defined as ffmpeg cameras which have a "source path" rather than a "host" defined.
mysql> SELECT Id, Name, Type, Device, Host, Channel, Function, Enabled FROM Monitors; +----+----------+--------+-------------+---------------------+---------+----------+---------+ | Id | Name | Type | Device | Host | Channel | Function | Enabled | +----+----------+--------+-------------+---------------------+---------+----------+---------+ | 1 | Dericam | Remote | /dev/video0 | camera.thepoint.org | 0 | Modect | 1 | | 2 | Fisheye | Ffmpeg | /dev/video0 | NULL | 0 | Modect | 1 | | 3 | Backdoor | Ffmpeg | /dev/video0 | NULL | 0 | Modect | 1 | | 4 | Lounge | Ffmpeg | /dev/video0 | NULL | 0 | Modect | 0 | +----+----------+--------+-------------+---------------------+---------+----------+---------+ 4 rows in set (0.00 sec)
This means that, for example, when row[4] is assigned to the host string variable for camera 2, 3 or 4 it is set to NULL (0x0) which causes an exception on the first assignment attempt. See https://stackoverflow.com/questions/11617552/c-assigning-null-to-a-string/53785687 for more about assigning NULL to strings.
Here's my simplistic patch just for the "host" string field:
# git --no-pager diff zmserver.cpp
diff --git a/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp b/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp
index 96365f3468..0dd1f8d5e2 100644
--- a/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp
+++ b/mythplugins/mythzoneminder/mythzmserver/zmserver.cpp
@@ -986,7 +986,10 @@ void ZMServer::handleGetMonitorStatus(void)
string id = row[0];
string type = row[2];
string device = row[3];
- string host = row[4];
+ string host = "";
+ if (row[4]) { // Dug FIXME.
+ host = row[4];
+ }
string channel = row[5];
string function = row[6];
string enabled = row[7];
@@ -1734,7 +1737,7 @@ void ZMServer::getMonitorList(void)
m->m_function = row[8];
m->m_enabled = atoi(row[9]);
m->m_device = row[10];
- m->m_host = row[11];
+ m->m_host = row[11] || ""; // Dug FIXME.
m->m_controllable = atoi(row[12]);
m->m_trackMotion = atoi(row[13]);
With the above fix in place all my cameras work in mythzoneminder and mythzmserver happily runs in the background.
Again, I'm no C++ programmer but the above lame fix stopped zmserver.cpp giving a segmentation fault on startup.
I'm not even sure how to submit fixes to mythtv. I think all the fields from the database should be checked that they are not NULL or the query itself could, perhaps, be altered to use IFNULL('field', \'\').
Cheers,
Doug

Oops, i should have given this a better title... I started writing this when I thought it was due to strlen() being called with a NULL. Perhaps, a better title would be "mythzmserver NULL assumptions".