Public bug reported:

powerman fails to build from source in Ubuntu stonking (all
architectures).

== Build Error ==

hostlist.c: In function '_parse_single_range':
hostlist.c:1403:12: error: assignment discards 'const' qualifier from pointer 
target type [-Werror=discarded-qualifiers]
 1403 |     if ((p = strchr(str, '-'))) {
      |            ^
cc1: all warnings being treated as errors

== Root Cause ==

glibc now provides two const-preserving overloads of strchr():

  extern char *strchr (char *__s, int __c);
  extern const char *strchr (const char *__s, int __c);

In src/liblsd/hostlist.c, _parse_single_range() takes a `const char *str`
argument, strdup's it into a mutable `orig` buffer, but then incorrectly calls
strchr() and strtoul() on the original const pointer `str`. Assigning the result
of strchr(const char*, ...) to `char *p` discards the const qualifier, which is
now rejected by -Werror=discarded-qualifiers.

This is also a latent correctness bug: the code does `*p++ = '\0'` through `p`,
which would write into the const string `str`. The mutable copy `orig` should be
used throughout instead.

== Fix ==

Use `orig` (the mutable strdup copy) instead of `str` for
strchr/strtoul:

--- a/src/liblsd/hostlist.c
+++ b/src/liblsd/hostlist.c
@@ -1400,13 +1400,13 @@ static int _parse_single_range(const cha
-    if ((p = strchr(str, '-'))) {
+    if ((p = strchr(orig, '-'))) {
         *p++ = '\0';
         if (*p == '-')     /* do NOT allow negative numbers */
             goto error;
     }
-    range->lo = strtoul(str, &q, 10);
+    range->lo = strtoul(orig, &q, 10);
-    if (q == str)
+    if (q == orig)
         goto error;

== References ==

PPA build log: https://launchpad.net/~hectorcao/+archive/ubuntu/net-
snmp-transition/+build/32908548

** Affects: powerman (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: ftbfs stonking stonking-net-snmp-transition

** Tags added: stonking-net-snmp-transition

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2154427

Title:
  powerman: FTBFS in stonking - const qualifier discarded in hostlist.c

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/powerman/+bug/2154427/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to