diff options
author | Mingli Yu <Mingli.Yu@windriver.com> | 2018-09-21 11:43:10 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-09-21 18:45:47 -0700 |
commit | c32b26ce8d43f39aecf4b53175690ee66e03c376 (patch) | |
tree | ea52bdb7cea7e2f1ee8a7101d06a60d45758278c /meta | |
parent | 4aa1f858ef9a23f003031753dbe8b948fa5d9ebb (diff) | |
download | poky-c32b26ce8d43f39aecf4b53175690ee66e03c376.tar.gz |
glibc: fix Segmentation fault in gethostid.c
Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
A NULL value can happen with certain gethostbyname_r failures.
Before this patch, there is a Segmentation fault
as below:
# /mybuild/hostid
Segmentation fault
# gdb /mybuild/hostid
GNU gdb (GDB) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-wrs-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /mybuild/hostid...done.
(gdb) r
Starting program: /mybuild/hostid
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125
125 memcpy (&in, hp->h_addr,
(gdb) bt
#0 0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125
#1 0x0000555555555159 in main ()
# cat /mybuild/hostid.c
#include <stdio.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
long hostid;
hostid = gethostid();
printf("the hostid is %ld\n", hostid);
}
(From OE-Core rev: 92c266fd9b1c4034a13bd5b102d1817df388a7b5)
Signed-off-by: Mingli Yu <Mingli.Yu@windriver.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/recipes-core/glibc/glibc/0001-Linux-gethostid-Check-for-NULL-value-from-gethostbyn.patch | 38 | ||||
-rw-r--r-- | meta/recipes-core/glibc/glibc_2.28.bb | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/meta/recipes-core/glibc/glibc/0001-Linux-gethostid-Check-for-NULL-value-from-gethostbyn.patch b/meta/recipes-core/glibc/glibc/0001-Linux-gethostid-Check-for-NULL-value-from-gethostbyn.patch new file mode 100644 index 0000000000..3cf3266ba1 --- /dev/null +++ b/meta/recipes-core/glibc/glibc/0001-Linux-gethostid-Check-for-NULL-value-from-gethostbyn.patch | |||
@@ -0,0 +1,38 @@ | |||
1 | From e7d22db29cfdd2f1fb97a70a76fa53d151569945 Mon Sep 17 00:00:00 2001 | ||
2 | From: Mingli Yu <Mingli.Yu@windriver.com> | ||
3 | Date: Thu, 20 Sep 2018 12:41:13 +0200 | ||
4 | Subject: [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679] | ||
5 | |||
6 | A NULL value can happen with certain gethostbyname_r failures. | ||
7 | |||
8 | (cherry picked from commit 1214ba06e6771acb953a190091b0f6055c64fd25) | ||
9 | |||
10 | Upstream-Status: Backport [https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=1214ba06e6771acb953a190091b0f6055c64fd25] | ||
11 | |||
12 | Signed-off-by: Mingli Yu <mingli.yu@windriver.com> | ||
13 | --- | ||
14 | sysdeps/unix/sysv/linux/gethostid.c | 4 ++-- | ||
15 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
16 | |||
17 | diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c | ||
18 | index 2e20f034dc..ee0190e7f9 100644 | ||
19 | --- a/sysdeps/unix/sysv/linux/gethostid.c | ||
20 | +++ b/sysdeps/unix/sysv/linux/gethostid.c | ||
21 | @@ -102,12 +102,12 @@ gethostid (void) | ||
22 | { | ||
23 | int ret = __gethostbyname_r (hostname, &hostbuf, | ||
24 | tmpbuf.data, tmpbuf.length, &hp, &herr); | ||
25 | - if (ret == 0) | ||
26 | + if (ret == 0 && hp != NULL) | ||
27 | break; | ||
28 | else | ||
29 | { | ||
30 | /* Enlarge the buffer on ERANGE. */ | ||
31 | - if (herr == NETDB_INTERNAL && errno == ERANGE) | ||
32 | + if (ret != 0 && herr == NETDB_INTERNAL && errno == ERANGE) | ||
33 | { | ||
34 | if (!scratch_buffer_grow (&tmpbuf)) | ||
35 | return 0; | ||
36 | -- | ||
37 | 2.17.1 | ||
38 | |||
diff --git a/meta/recipes-core/glibc/glibc_2.28.bb b/meta/recipes-core/glibc/glibc_2.28.bb index df60ba8445..804b7891ec 100644 --- a/meta/recipes-core/glibc/glibc_2.28.bb +++ b/meta/recipes-core/glibc/glibc_2.28.bb | |||
@@ -47,6 +47,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \ | |||
47 | file://0030-intl-Emit-no-lines-in-bison-generated-files.patch \ | 47 | file://0030-intl-Emit-no-lines-in-bison-generated-files.patch \ |
48 | file://0031-sysdeps-ieee754-prevent-maybe-uninitialized-errors.patch \ | 48 | file://0031-sysdeps-ieee754-prevent-maybe-uninitialized-errors.patch \ |
49 | file://0032-soft-fp-ignore-maybe-uninitialized.patch \ | 49 | file://0032-soft-fp-ignore-maybe-uninitialized.patch \ |
50 | file://0001-Linux-gethostid-Check-for-NULL-value-from-gethostbyn.patch \ | ||
50 | " | 51 | " |
51 | 52 | ||
52 | NATIVESDKFIXES ?= "" | 53 | NATIVESDKFIXES ?= "" |