[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [virt-tools-list] [libosinfo] Don't entertain empty ID headers from ISOs



Hi,

I ran a few more tests with this patch, and it fixes detection of ubuntu
11.10 isos, but only by chance... Ubuntu 11.10 isos have a volume-id, but
no publisher-id nor system-id. pvd.system and pvd.publisher end up as
strings with whitespace with these isos: "        " (the actual strings are
longer than that).

on_pvd_read has this test

    if (data->pvd.volume[0] &&
        (data->pvd.system[0] == 0 && data->pvd.publisher[0] == 0)) {
        g_set_error(&error,
                    OSINFO_MEDIA_ERROR,
                    OSINFO_MEDIA_ERROR_INSUFFIENT_METADATA,
                    "Insufficient metadata on installation media");

        goto ON_ERROR;
    }

It's meant to error out if volume-id is set, but system-id and publisher-id
are not set. This is exactly what happens on the ubuntu iso, but an error
is not triggered because the strings are not actually empty, but full of
blank space.

We've got 2 issues to fix here:
1) fix the detection of empty strings
2) fix this test so that an error is not triggered with ubuntu isos

For 2), I think we should error out if volume-id is empty, but don't
require anything more than that to be set, ie this patch :

diff --git a/osinfo/osinfo_media.c b/osinfo/osinfo_media.c
index 0c54c21..26d3248 100644
--- a/osinfo/osinfo_media.c
+++ b/osinfo/osinfo_media.c
@@ -514,6 +514,9 @@ static gboolean is_str_empty(const gchar *str) {
     guint8 i;
     gboolean ret = TRUE;
 
+    if ((str == NULL) || (*str == 0))
+        return TRUE;
+
     for (i = 0; i < strlen (str); i++)
         if (!g_ascii_isspace (str[i])) {
            ret = FALSE;
@@ -571,15 +574,15 @@ static void on_svd_read (GObject *source,
                             OSINFO_MEDIA_PROP_URL,
                             uri);
     g_free(uri);
-    if (data->pvd.volume[0] != 0 && !is_str_empty (data->pvd.volume))
+    if (!is_str_empty (data->pvd.volume))
         osinfo_entity_set_param(OSINFO_ENTITY(ret),
                                 OSINFO_MEDIA_PROP_VOLUME_ID,
                                 data->pvd.volume);
-    if (data->pvd.system[0] != 0 && !is_str_empty (data->pvd.system))
+    if (!is_str_empty (data->pvd.system))
         osinfo_entity_set_param(OSINFO_ENTITY(ret),
                                 OSINFO_MEDIA_PROP_SYSTEM_ID,
                                 data->pvd.system);
-    if (data->pvd.publisher[0] != 0 && !is_str_empty
     (data->pvd.publisher))
+    if (!is_str_empty (data->pvd.publisher))
         osinfo_entity_set_param(OSINFO_ENTITY(ret),
                                 OSINFO_MEDIA_PROP_PUBLISHER_ID,
                                 data->pvd.publisher);
@@ -623,8 +626,7 @@ static void on_pvd_read (GObject *source,
     data->pvd.system[MAX_SYSTEM - 1] = 0;
     data->pvd.publisher[MAX_PUBLISHER - 1] = 0;
 
-    if (data->pvd.volume[0] &&
-        (data->pvd.system[0] == 0 && data->pvd.publisher[0] == 0)) {
+    if (is_str_empty(data->pvd.volume)) {
         g_set_error(&error,
                     OSINFO_MEDIA_ERROR,
                     OSINFO_MEDIA_ERROR_INSUFFIENT_METADATA,

Christophe

Attachment: pgpP21XdGE7oX.pgp
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]