diff options
author | Mark Kettenis <kettenis@gnu.org> | 2000-11-13 20:15:25 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@gnu.org> | 2000-11-13 20:15:25 +0000 |
commit | fbfdeab348c3173bb9607565efab2882e92e0965 (patch) | |
tree | 390243f6a2698623b85d2e7cd9fb585ba8132cbd | |
parent | 1ed9a93478159ebdce5f03cf94b45f3486b79f0e (diff) | |
download | glibc-fbfdeab348c3173bb9607565efab2882e92e0965.tar.gz glibc-fbfdeab348c3173bb9607565efab2882e92e0965.tar.xz glibc-fbfdeab348c3173bb9607565efab2882e92e0965.zip |
* hurd/get-host.c (_hurd_get_host_config): Fix possible buffer underrun and make sure the result is null terminated even if there is no trailing newline.
2000-11-13 Marcus Brinkmann <marcus@gnu.org> * hurd/get-host.c (_hurd_get_host_config): Fix possible buffer underrun and make sure the result is null terminated even if there is no trailing newline.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | hurd/get-host.c | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index e2b9ef9cf7..2f6df1dc36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-11-13 Marcus Brinkmann <marcus@gnu.org> + + * hurd/get-host.c (_hurd_get_host_config): Fix possible buffer + underrun and make sure the result is null terminated even if there + is no trailing newline. + 2000-11-13 Jakub Jelinek <jakub@redhat.com> * sysdeps/alpha/fpu/libm-test-ulps: Update. diff --git a/hurd/get-host.c b/hurd/get-host.c index 7c55afa0ae..93890c724e 100644 --- a/hurd/get-host.c +++ b/hurd/get-host.c @@ -1,5 +1,5 @@ /* Get a host configuration item kept as the whole contents of a file. - Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -70,11 +70,18 @@ _hurd_get_host_config (const char *item, char *buf, size_t buflen) *buf = '\0'; return 0; } - + /* Remove newlines in case someone wrote the file by hand. */ - while (buf[nread - 1] == '\n') + while (buf[nread - 1] == '\n' && nread > 0) buf[--nread] = '\0'; + /* Null-terminate the result if there is enough space. */ + if (nread < buflen) + buf[nread] = '\0'; + else + if (buf[nread - 1] != '\0') + more = 1; + if (more) /* If we didn't read the whole file, tell the caller to use a bigger buffer next time. */ |