From: Bruno Haible Date: Fri, 2 Jun 2023 23:22:24 +0000 (+0200) Subject: libtextstyle: Don't crash if xgethostname() returns NULL. X-Git-Tag: v0.22~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87fa86ba0ea90df0563d92a6bd800f12830743b6;p=thirdparty%2Fgettext.git libtextstyle: Don't crash if xgethostname() returns NULL. Pinpointed by gcc 13 warning: warning: dereference of possibly-NULL ā€˜p’ [CWE-690] [-Wanalyzer-possible-null-dereference] * libtextstyle/gnulib-local/lib/term-ostream.oo.c (term_ostream_create): If xgethostname() returns NULL, use a dummy hash code. --- diff --git a/libtextstyle/gnulib-local/lib/term-ostream.oo.c b/libtextstyle/gnulib-local/lib/term-ostream.oo.c index 99d7c7e4d..36618a678 100644 --- a/libtextstyle/gnulib-local/lib/term-ostream.oo.c +++ b/libtextstyle/gnulib-local/lib/term-ostream.oo.c @@ -2705,9 +2705,12 @@ term_ostream_create (int fd, const char *filename, ttyctl_t tty_control) char *hostname = xgethostname (); { /* Compute a hash code, like in gnulib/lib/hash-pjw.c. */ uint32_t h = 0; - const char *p; - for (p = hostname; *p; p++) - h = (unsigned char) *p + ((h << 9) | (h >> (32 - 9))); + if (hostname != NULL) + { + const char *p; + for (p = hostname; *p; p++) + h = (unsigned char) *p + ((h << 9) | (h >> (32 - 9))); + } stream->hostname_hash = h; } free (hostname);