From: Sebastian Dröge Date: Fri, 9 Jun 2023 07:28:43 +0000 (+0300) Subject: ptp: Correctly parse clock ID from the commandline parameters in the helper X-Git-Tag: 1.22.7~219 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=06586fd92faa6dc7eca2007a54ced3000ed7520b;p=platform%2Fupstream%2Fgstreamer.git ptp: Correctly parse clock ID from the commandline parameters in the helper Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2652 Part-of: --- diff --git a/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c b/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c index 4e8ab36..0531944 100644 --- a/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c +++ b/subprojects/gstreamer/libs/gst/helpers/gst-ptp-helper.c @@ -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},