External Issue: SysError.SystemError.fromSyserr() halts on negative arguments

18103, "cassella", "SysError.SystemError.fromSyserr() halts on negative arguments", "2021-07-23T00:42:37Z"

Summary of Problem

Steps to Reproduce

Source Code:

use SysError;

var e = SystemError.fromSyserr(-1);

writeln(e);
(null):430: error: Out of memory allocating "io buffer or bytes"

I haven't run any tests to verify it, but I believe it's due to
src/qio/sys.c sys_strerror_internal():

  while( 1 ) {
    newbuf = (char*) qio_realloc(buf, buf_sz + extra_space);
    if( ! newbuf ) {
      qio_free(buf);
      return ENOMEM;
    }
    buf = newbuf;
    got = sys_xsi_strerror_r(error, buf, buf_sz);
    if( got == 0 ) break;
    if( got == -1 && errno != ERANGE ) {
      err_out = errno;
      break;
    }
    buf_sz *= 2; // try again with a bigger buffer.
  }

and src/qio/sys_xsi_strerror_r.c:

int sys_xsi_strerror_r(int errnum, char* buf, size_t buflen)
{
#ifdef HAS_STRERROR_R
  return strerror_r(errnum, buf, buflen);
#else

The man page for strerror_r() says

RETURN VALUE

 ...

 The XSI-compliant strerror_r() function returns 0 on success.  On
 error, a (positive) error number is returned (since glibc 2.13), or
 -1 is returned and errno is set to indicate the error (glibc versions
 before 2.13).

So strerror_r() now returns a positive error number, which
sys_xsi_strerror_r() in turn returns. That doesn't hit any of the
cases to break out of the loop in sys_strerror_internal(), so it
doubles the size of the buffer and tries again. Since that doesn't
fix the problem, it just keeps making the buffer larger until it runs
out of memory.

Associated Future Test(s):

None yet.

The man page suggests this failure would happen only on systems with
glibc >= 2.13.

Configuration Information

chpl version 1.25.0 pre-release (5be7c2df77)
Copyright 2020-2021 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)

CHPL_TARGET_PLATFORM: linux64
CHPL_TARGET_COMPILER: gnu
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native *
CHPL_LOCALE_MODEL: flat
CHPL_COMM: gasnet *
  CHPL_COMM_SUBSTRATE: udp
  CHPL_GASNET_SEGMENT: everything
CHPL_TASKS: qthreads
CHPL_LAUNCHER: amudprun
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
  CHPL_NETWORK_ATOMICS: none
CHPL_GMP: none
CHPL_HWLOC: bundled
CHPL_RE2: bundled
CHPL_LLVM: none *
CHPL_AUX_FILESYS: none

gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0