Handle NULL in str2hge()
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 9 Jun 2008 06:31:00 +0000 (09:31 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 9 Jun 2008 06:31:00 +0000 (09:31 +0300)
- at least apt-rpm expects to pass empty version as NULL to rpmdsSingle(),
  don't blow up...

lib/rpmds.c

index 565dace..2d49ec6 100644 (file)
@@ -90,10 +90,16 @@ static int dsType(rpmTag tag,
 static const char ** str2hge(const char *str)
 {
     const char ** arr;
-    char *t = xmalloc(sizeof(*arr) + strlen(str) + 1);
+    size_t slen = str ? strlen(str) + 1 : 0;
+    char *t = xmalloc(sizeof(*arr) + slen);
     arr = (const char **) t;
-    t += sizeof(*arr);
-    strcpy(t, str);
+
+    if (str) {
+       t += sizeof(*arr);
+       strcpy(t, str);
+    } else {
+       t = NULL;
+    }
     arr[0] = t;
     return arr;
 }