ptp: Correctly parse clock ID from the commandline parameters in the helper
authorSebastian Dröge <sebastian@centricular.com>
Fri, 9 Jun 2023 07:28:43 +0000 (10:28 +0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 12 Jun 2023 11:29:25 +0000 (11:29 +0000)
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2652

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4813>

subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c

index 4e8ab36..0531944 100644 (file)
@@ -71,10 +71,37 @@ static gboolean verbose = FALSE;
 static guint64 clock_id = (guint64) - 1;
 static guint8 clock_id_array[8];
 
+static gboolean
+parse_clock_id (const gchar * option_name, const gchar * value, gpointer data,
+    GError ** err)
+{
+  gchar *endptr;
+  guint64 v;
+
+  errno = 0;
+  v = g_ascii_strtoull (value, &endptr, 16);
+  if (endptr == NULL || *endptr != '\0') {
+    g_set_error (err, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION,
+        "Cannot parse integer value \"%s\" for --clock-id", value);
+    return FALSE;
+  }
+
+  if (errno != 0) {
+    g_set_error (err, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION,
+        "Cannot parse integer value \"%s\" for --clock-id: %s", value,
+        g_strerror (errno));
+    return FALSE;
+  }
+
+  clock_id = v;
+
+  return TRUE;
+}
+
 static GOptionEntry opt_entries[] = {
   {"interface", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &ifaces,
       "Interface to listen on", NULL},
-  {"clock-id", 'c', 0, G_OPTION_ARG_INT64, &clock_id,
+  {"clock-id", 'c', 0, G_OPTION_ARG_CALLBACK, parse_clock_id,
       "PTP clock id", NULL},
   {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
       "Be verbose", NULL},