[libvirt PATCH 0/2] Be more accepting of variations in dnsmasq version string

pihole thought it would be cute to include "pihole-" at the beginning of the version of the dnsmasq build they include... https://gitlab.com/libvirt/libvirt/-/issues/29 Laine Stump (2): util: virSkipToDigit() util: Skip over any extra verbiage preceding version in dnsmasq version string src/libvirt_private.syms | 1 + src/util/virdnsmasq.c | 4 +++- src/util/virstring.c | 18 ++++++++++++++++++ src/util/virstring.h | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) -- 2.29.2

This function skips over the beginning of a string until it reaches a decimal digit (0-9) or the NULL at the end of the string. The original pointer is modified in place (similar to virSkipSpaces()). Signed-off-by: Laine Stump <laine@redhat.com> --- src/libvirt_private.syms | 1 + src/util/virstring.c | 18 ++++++++++++++++++ src/util/virstring.h | 1 + 3 files changed, 20 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c67bd2504a..c325040b60 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3217,6 +3217,7 @@ virStorageFileBackendRegister; virSkipSpaces; virSkipSpacesAndBackslash; virSkipSpacesBackwards; +virSkipToDigit; virStrcpy; virStringBufferIsPrintable; virStringFilterChars; diff --git a/src/util/virstring.c b/src/util/virstring.c index 5578a5545b..521f2de3f6 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -752,6 +752,24 @@ virSkipSpacesAndBackslash(const char **str) *str = cur; } + +/** + * virSkipToDigit: + * @str: pointer to the char pointer used + * + * Skip over any character that is not 0-9 + */ +void +virSkipToDigit(const char **str) +{ + const char *cur = *str; + + while (*cur && !g_ascii_isdigit(*cur)) + cur++; + *str = cur; +} + + /** * virTrimSpaces: * @str: string to modify to remove all trailing spaces diff --git a/src/util/virstring.h b/src/util/virstring.h index 210e43a953..55547b040a 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -110,6 +110,7 @@ int virDoubleToStr(char **strp, double number) void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1); void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1); +void virSkipToDigit(const char **str) ATTRIBUTE_NONNULL(1); void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1); void virSkipSpacesBackwards(const char *str, char **endp) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -- 2.29.2

dnsmasq usually prints out a version string like this: Dnsmasq version 2.82 [...] but a user reported that the build of dnsmasq included with pihole has a version string like this: Dnsmasq version pi-hole-2.81 [...] We parse the dnsmasq version number to figure out if the dnsmasq binary supports certain features. Since we expect the version number (and it must be only numbers!) to start on the first non-space after the string "Dnsmasq version", we fail to parse this format of the version string. Rather than spending a bunch of time trying to get pihole to change that, we can just make our parsing more permissive - after searching for "Dnsmasq version", we'll skip ahead to the first decimal digit, rather than just the first non-space. (NB: The features we're checking for purely by looking at version number have been in all releases of dnsmasq since at least 2012, so we could actually just remove the reading of the version number completely. However it's possible (although *highly* unlikely) that some new feature would be added to dnsmasq in the future and we would need to add that code back.) Resolves: https://gitlab.com/libvirt/libvirt/-/issues/29 Signed-off-by: Laine Stump <laine@redhat.com> --- src/util/virdnsmasq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index 5f477c976d..63ac088e06 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -638,7 +638,9 @@ dnsmasqCapsSetFromBuffer(dnsmasqCapsPtr caps, const char *buf) p = STRSKIP(buf, DNSMASQ_VERSION_STR); if (!p) goto fail; - virSkipSpaces(&p); + + virSkipToDigit(&p); + if (virParseVersionString(p, &caps->version, true) < 0) goto fail; -- 2.29.2

On a Thursday in 2021, Laine Stump wrote:
pihole thought it would be cute to include "pihole-" at the beginning of the version of the dnsmasq build they include...
https://gitlab.com/libvirt/libvirt/-/issues/29
Laine Stump (2): util: virSkipToDigit() util: Skip over any extra verbiage preceding version in dnsmasq version string
src/libvirt_private.syms | 1 + src/util/virdnsmasq.c | 4 +++- src/util/virstring.c | 18 ++++++++++++++++++ src/util/virstring.h | 1 + 4 files changed, 23 insertions(+), 1 deletion(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Laine Stump