Re: [OE-core] [PATCH v2] glibc: fix Segmentation fault in gethostid.c

2018-09-20 Thread Yu, Mingli

Will send out v3 with the update from glibc upstream.

Thanks,

On 2018年09月18日 17:47, mingli...@windriver.com wrote:

From: Mingli Yu 

When run test program hostid, it encounters
Segmentation fault as hp is NULL.

  # cat /mybuild/hostid.c
  #include 
  #include 

  int
  main(int argc, char *argv[])
  {
 long hostid;
 hostid = gethostid();
 printf("the hostid is %ld\n", hostid);

  }

  # gcc -o /mybuild/hostid /mybuild/hostid.c
  # /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 
  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:
  .
  Find the GDB manual and other documentation resources online at:
 .

  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.
  0x77f0330e in gethostid () at 
../sysdeps/unix/sysv/linux/gethostid.c:125
  125 memcpy (, hp->h_addr,
  (gdb) bt
  #0  0x77f0330e in gethostid () at 
../sysdeps/unix/sysv/linux/gethostid.c:125
  #1  0x5159 in main ()

Signed-off-by: Mingli Yu 
---
  .../0001-gethostid.c-check-the-value-of-hp.patch   | 75 ++
  meta/recipes-core/glibc/glibc_2.28.bb  |  1 +
  2 files changed, 76 insertions(+)
  create mode 100644 
meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch

diff --git 
a/meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch 
b/meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch
new file mode 100644
index 00..04d1662361
--- /dev/null
+++ b/meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch
@@ -0,0 +1,75 @@
+From 84cc79a003cf1a29e0a45ee76b67a3800d9e412e Mon Sep 17 00:00:00 2001
+From: Mingli Yu 
+Date: Tue, 18 Sep 2018 07:29:27 +
+Subject: [PATCH] gethostid.c: check the value of hp
+
+Fix Segmentation fault in gethostid.c
+
+When run test program hostid, it encounters
+Segmentation fault as hp is NULL.
+
+  # cat /mybuild/hostid.c
+  #include 
+  #include 
+
+  int
+  main(int argc, char *argv[])
+  {
+long hostid;
+hostid = gethostid();
+printf("the hostid is %ld\n", hostid);
+  }
+
+  # gcc -o /mybuild/hostid /mybuild/hostid.c
+  # /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 
+  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:
+  .
+  Find the GDB manual and other documentation resources online at:
+  .
+
+   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.
+   0x77f0330e in gethostid () at 
../sysdeps/unix/sysv/linux/gethostid.c:125
+   125  memcpy (, hp->h_addr,
+   (gdb) bt
+#0  0x77f0330e in gethostid () at 
../sysdeps/unix/sysv/linux/gethostid.c:125
+#1  0x5159 in main ()
+
+Upstream-Status: 
Submitted[https://sourceware.org/bugzilla/show_bug.cgi?id=23679]
+
+Signed-off-by: Mingli Yu 
+---
+ sysdeps/unix/sysv/linux/gethostid.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/sysdeps/unix/sysv/linux/gethostid.c 
b/sysdeps/unix/sysv/linux/gethostid.c
+index 2e20f034dc..5904b61c40 100644
+--- a/sysdeps/unix/sysv/linux/gethostid.c
 b/sysdeps/unix/sysv/linux/gethostid.c
+@@ -102,7 +102,7 @@ gethostid (void)
+ {
+   int ret = __gethostbyname_r (hostname, ,
+  tmpbuf.data, tmpbuf.length, , );
+-  if (ret == 0)
++  if (ret == 0 && hp != NULL)
+   break;
+   else
+   {
+--
+2.13.3
+
diff --git a/meta/recipes-core/glibc/glibc_2.28.bb 
b/meta/recipes-core/glibc/glibc_2.28.bb
index 0ebbaf9610..0a8fa0c25f 100644
--- a/meta/recipes-core/glibc/glibc_2.28.bb
+++ b/meta/recipes-core/glibc/glibc_2.28.bb

[OE-core] [PATCH v2] glibc: fix Segmentation fault in gethostid.c

2018-09-18 Thread mingli.yu
From: Mingli Yu 

When run test program hostid, it encounters
Segmentation fault as hp is NULL.

 # cat /mybuild/hostid.c
 #include 
 #include 

 int
 main(int argc, char *argv[])
 {
long hostid;
hostid = gethostid();
printf("the hostid is %ld\n", hostid);

 }

 # gcc -o /mybuild/hostid /mybuild/hostid.c
 # /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 
 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:
 .
 Find the GDB manual and other documentation resources online at:
.

 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.
 0x77f0330e in gethostid () at 
../sysdeps/unix/sysv/linux/gethostid.c:125
 125  memcpy (, hp->h_addr,
 (gdb) bt
 #0  0x77f0330e in gethostid () at 
../sysdeps/unix/sysv/linux/gethostid.c:125
 #1  0x5159 in main ()

Signed-off-by: Mingli Yu 
---
 .../0001-gethostid.c-check-the-value-of-hp.patch   | 75 ++
 meta/recipes-core/glibc/glibc_2.28.bb  |  1 +
 2 files changed, 76 insertions(+)
 create mode 100644 
meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch

diff --git 
a/meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch 
b/meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch
new file mode 100644
index 00..04d1662361
--- /dev/null
+++ b/meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch
@@ -0,0 +1,75 @@
+From 84cc79a003cf1a29e0a45ee76b67a3800d9e412e Mon Sep 17 00:00:00 2001
+From: Mingli Yu 
+Date: Tue, 18 Sep 2018 07:29:27 +
+Subject: [PATCH] gethostid.c: check the value of hp
+
+Fix Segmentation fault in gethostid.c
+
+When run test program hostid, it encounters
+Segmentation fault as hp is NULL.
+
+  # cat /mybuild/hostid.c
+  #include 
+  #include 
+
+  int
+  main(int argc, char *argv[])
+  {
+long hostid;
+hostid = gethostid();
+printf("the hostid is %ld\n", hostid);
+  }
+ 
+  # gcc -o /mybuild/hostid /mybuild/hostid.c
+  # /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 
+  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:
+  .
+  Find the GDB manual and other documentation resources online at:
+  .
+ 
+   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.
+   0x77f0330e in gethostid () at 
../sysdeps/unix/sysv/linux/gethostid.c:125
+   125  memcpy (, hp->h_addr,
+   (gdb) bt
+#0  0x77f0330e in gethostid () at 
../sysdeps/unix/sysv/linux/gethostid.c:125
+#1  0x5159 in main ()
+
+Upstream-Status: 
Submitted[https://sourceware.org/bugzilla/show_bug.cgi?id=23679]
+
+Signed-off-by: Mingli Yu 
+---
+ sysdeps/unix/sysv/linux/gethostid.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/sysdeps/unix/sysv/linux/gethostid.c 
b/sysdeps/unix/sysv/linux/gethostid.c
+index 2e20f034dc..5904b61c40 100644
+--- a/sysdeps/unix/sysv/linux/gethostid.c
 b/sysdeps/unix/sysv/linux/gethostid.c
+@@ -102,7 +102,7 @@ gethostid (void)
+ {
+   int ret = __gethostbyname_r (hostname, ,
+  tmpbuf.data, tmpbuf.length, , );
+-  if (ret == 0)
++  if (ret == 0 && hp != NULL)
+   break;
+   else
+   {
+-- 
+2.13.3
+
diff --git a/meta/recipes-core/glibc/glibc_2.28.bb 
b/meta/recipes-core/glibc/glibc_2.28.bb
index 0ebbaf9610..0a8fa0c25f 100644
--- a/meta/recipes-core/glibc/glibc_2.28.bb
+++ b/meta/recipes-core/glibc/glibc_2.28.bb
@@ -45,6 +45,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \