Opened 5 months ago

Closed 4 months ago

Last modified 2 months ago

#13466 closed Bug Report - Crash (fixed)

mythzmserver stdlib assumptions

Reported by: dscoular Owned by: Paul Harrison <pharrison@…>
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

Change History (5)

comment:1 Changed 5 months ago by dscoular

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".

comment:2 Changed 4 months ago by Paul Harrison <pharrison@…>

Owner: set to Paul Harrison <pharrison@…>
Resolution: fixed
Status: newclosed

In 7924ad992c/mythtv:

mythzmserver: don't try to get the shared memory pointers for a disabled Monitor

Also allow for a NULL result for the Host field in the Monitors table.
Fixes #13466

comment:3 Changed 4 months ago by Paul Harrison <pharrison@…>

In 84e5caeba/mythtv:

mythzmserver: don't try to get the shared memory pointers for a disabled Monitor

Also allow for a NULL result for the Host field in the Monitors table.
Fixes #13466

(cherry picked from commit 7924ad992c75c2dad04eef992d51c349d9e4a64d)

comment:4 Changed 4 months ago by Paul Harrison <pharrison@…>

In 83e2701720/mythtv:

mythzmserver: fix merge error after 84e5caebaa

Refs #13466

comment:5 Changed 2 months ago by Stuart Auchterlonie

Milestone: needs_triage30.1
Note: See TracTickets for help on using tickets.