]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libtextstyle: Don't crash if xgethostname() returns NULL.
authorBruno Haible <bruno@clisp.org>
Fri, 2 Jun 2023 23:22:24 +0000 (01:22 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 2 Jun 2023 23:22:24 +0000 (01:22 +0200)
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.

libtextstyle/gnulib-local/lib/term-ostream.oo.c

index 99d7c7e4d1ad1720b736813d48b37ed6515dc05f..36618a67810133d21d635fecd9f4600207cefc8a 100644 (file)
@@ -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);