]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
urlparser: Fixes in URIPARSER
authorJaroslav Kysela <perex@perex.cz>
Wed, 16 Apr 2014 20:48:41 +0000 (22:48 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 5 May 2014 20:00:36 +0000 (22:00 +0200)
src/url.c

index 8f0c38d3059f2c29b0544bf23b61cfe06852aafa..c9a8cd6006db8785d2fac68c0d0c890c491cde9d 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -91,6 +91,7 @@ urlparse ( const char *str, url_t *url )
   if (x.first) {\
     size_t len = x.afterLast - x.first;\
     strncpy(y, x.first, len);\
+    y[len] = '\0';\
   } else {\
     y[0] = '\0';\
   }
@@ -107,7 +108,10 @@ urlparse ( const char *str, url_t *url )
   path       = uri.pathHead;
   while (path) {
     uri_copy_static(buf, path->text);
-    url->path = realloc(url->path, strlen(url->path) + strlen(buf) + 2);
+    if (url->path)
+      url->path = realloc(url->path, strlen(url->path) + strlen(buf) + 2);
+    else
+      url->path = calloc(1, strlen(buf) + 2);
     strcat(url->path, "/");
     strcat(url->path, buf);
     path = path->next;
@@ -115,10 +119,12 @@ urlparse ( const char *str, url_t *url )
   // TODO: query/fragment
 
   /* Split user/pass */
-  s = strstr(url->user, ":");
-  if (s) {
-    strcpy(url->pass, s+1);
-    *s = 0;
+  if (url->user) {
+    s = strstr(url->user, ":");
+    if (s) {
+      strcpy(url->pass, s+1);
+      *s = 0;
+    }
   }
 
   /* Cleanup */