From b8d3badb18c8804e2edc6104883ac52c00ec04ec Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 8 May 2006 14:35:20 +0000 Subject: [PATCH] gst/rtsp/rtspurl.c: Make parsing of urls suck slightly less. Original commit message from CVS: * gst/rtsp/rtspurl.c: (rtsp_url_parse): Make parsing of urls suck slightly less. --- ChangeLog | 5 +++++ gst/rtsp/rtspurl.c | 25 ++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5bd3111682..5e6cfb2dcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-05-08 Wim Taymans + + * gst/rtsp/rtspurl.c: (rtsp_url_parse): + Make parsing of urls suck slightly less. + 2006-05-08 Edward Hervey * autogen.sh: (CONFIGURE_DEF_OPT): diff --git a/gst/rtsp/rtspurl.c b/gst/rtsp/rtspurl.c index da7a8795b3..2f67560763 100644 --- a/gst/rtsp/rtspurl.c +++ b/gst/rtsp/rtspurl.c @@ -37,7 +37,7 @@ rtsp_url_parse (const gchar * urlstr, RTSPUrl ** url) res = g_new0 (RTSPUrl, 1); if (urlstr == NULL) - return RTSP_EINVAL; + goto invalid; p = (gchar *) urlstr; if (g_str_has_prefix (p, RTSP_PROTO)) { @@ -46,30 +46,31 @@ rtsp_url_parse (const gchar * urlstr, RTSPUrl ** url) } else if (g_str_has_prefix (p, RTSPU_PROTO)) { res->protocol = RTSP_PROTO_UDP; p += RTSPU_PROTO_LEN; - } else { - return RTSP_EINVAL; - } + } else + goto invalid; slash = strstr (p, "/"); - at = g_strrstr (p, "@"); + at = strstr (p, "@"); if (at && slash && at > slash) at = NULL; if (at) { - col = g_strrstr (p, ":"); + col = strstr (p, ":"); - if (col == NULL) - return RTSP_EINVAL; + /* must have a ':' and it must be before the '@' */ + if (col == NULL || col > at) + goto invalid; res->user = g_strndup (p, col - p); col++; res->passwd = g_strndup (col, col - at); + /* move to host */ p = at + 1; } - col = g_strrstr (p, ":"); + col = strstr (p, ":"); if (col) { res->host = g_strndup (p, col - p); p = col + 1; @@ -92,6 +93,12 @@ rtsp_url_parse (const gchar * urlstr, RTSPUrl ** url) *url = res; return RTSP_OK; + +invalid: + { + rtsp_url_free (res); + return RTSP_EINVAL; + } } void