[Libguestfs] [PATCH] osinfo: parse also single-digit version numbers

Pino Toscano ptoscano at redhat.com
Mon Jul 25 16:19:03 UTC 2016


Switch to guestfs_int_version_from_x_y_or_x to parse version numbers --
although, restrict the parsing to what could look like a valid version
number, to discard quickly version strings like "unknown".

This makes sure that Debian, Fedora, Mageia, and SLED ISOs have the
right version number.
---
 src/osinfo.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/osinfo.c b/src/osinfo.c
index 0caacfa..907580e 100644
--- a/src/osinfo.c
+++ b/src/osinfo.c
@@ -62,6 +62,7 @@
 
 #include "ignore-value.h"
 #include "glthread/lock.h"
+#include "c-ctype.h"
 
 #include "guestfs.h"
 #include "guestfs-internal.h"
@@ -548,9 +549,12 @@ parse_version (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo)
   CLEANUP_FREE char *content = NULL;
 
   content = (char *) xmlNodeGetContent (node);
-  if (content) {
+  /* We parse either "X.Y" or "X" as version strings, so try to parse
+   * only if the first character is a digit.
+   */
+  if (content && c_isdigit (content[0])) {
     struct version version;
-    int res = guestfs_int_version_from_x_y (g, &version, content);
+    int res = guestfs_int_version_from_x_y_or_x (g, &version, content);
     if (res < 0)
       return -1;
     else if (res > 0) {
-- 
2.7.4




More information about the Libguestfs mailing list