Fix segfault in 'getent hosts'.

resolves: #1075932
This commit is contained in:
Andreas Schneider 2014-03-14 11:18:30 +01:00
parent 5a6f95bcbe
commit 961e5cc226
2 changed files with 179 additions and 1 deletions

View File

@ -0,0 +1,171 @@
commit 64c082a393013e3fc9a0cce0afa5e426f55b5ccd
Author: Andreas Schneider <asn@samba.org>
AuthorDate: Thu Mar 13 10:20:46 2014 +0100
Commit: Andreas Schneider <asn@samba.org>
CommitDate: Thu Mar 13 13:43:13 2014 +0100
src: Fix segfault in 'getent hosts' without aliases.
The glibc's 'getent' always dereferences he->h_aliases[i], so we need
to allocate it.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
---
src/nss_wrapper.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index 5685fc6..94df6ac 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -1950,7 +1950,12 @@ static bool nwrap_he_parse_line(struct nwrap_cache *nwrap, char *line)
ed->ht.h_name = n;
- ed->ht.h_aliases = NULL;
+ /* glib's getent always dereferences he->h_aliases */
+ ed->ht.h_aliases = malloc(sizeof(char *));
+ if (ed->ht.h_aliases == NULL) {
+ return false;
+ }
+ ed->ht.h_aliases[0] = NULL;
/*
* Aliases
commit b928fe9ff92a237ee4cffadfa517d76a4e07d80c
Author: Andreas Schneider <asn@samba.org>
AuthorDate: Thu Mar 13 10:35:47 2014 +0100
Commit: Andreas Schneider <asn@samba.org>
CommitDate: Thu Mar 13 13:43:32 2014 +0100
tests: Add test_gethostent.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
---
tests/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 3b84829..5aab29e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -23,7 +23,7 @@ list(APPEND TEST_ENVIRONMENT NSS_WRAPPER_HOSTS=${CMAKE_CURRENT_BINARY_DIR}/hosts
list(APPEND TEST_ENVIRONMENT NSS_WRAPPER_MODULE_SO_PATH=${CMAKE_CURRENT_BINARY_DIR}/libnss_nwrap.so)
list(APPEND TEST_ENVIRONMENT NSS_WRAPPER_MODULE_FN_PREFIX=nwrap)
-set(NWRAP_TESTS testsuite test_getaddrinfo test_getnameinfo test_gethostby_name_addr)
+set(NWRAP_TESTS testsuite test_getaddrinfo test_getnameinfo test_gethostby_name_addr test_gethostent)
foreach(_NWRAP_TEST ${NWRAP_TESTS})
add_cmocka_test(${_NWRAP_TEST} ${_NWRAP_TEST}.c ${TESTSUITE_LIBRARIES})
commit f24dbf643575c764eb74bbc08de2ececc35f1659
Author: Andreas Schneider <asn@samba.org>
AuthorDate: Thu Mar 13 13:46:22 2014 +0100
Commit: Andreas Schneider <asn@samba.org>
CommitDate: Fri Mar 14 11:01:04 2014 +0100
tests: Add test_gethostent.c
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
---
tests/test_gethostent.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/tests/test_gethostent.c b/tests/test_gethostent.c
new file mode 100644
index 0000000..e95195f
--- /dev/null
+++ b/tests/test_gethostent.c
@@ -0,0 +1,61 @@
+#include "config.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+static void test_nwrap_gethostent(void **state)
+{
+ struct hostent *he;
+ uint32_t i;
+
+ (void)state; /* unused */
+
+ sethostent(0);
+
+ for (he = gethostent(); he != NULL; he = gethostent()) {
+ assert_non_null(he->h_addr_list);
+ assert_non_null(he->h_aliases);
+
+ for (i = 0; he->h_addr_list[i] != NULL; i++) {
+ char buf[INET6_ADDRSTRLEN];
+ uint32_t j;
+ const char *ip;
+
+ ip = inet_ntop(he->h_addrtype,
+ he->h_addr_list[i],
+ buf,
+ sizeof(buf));
+
+ printf("ip: %s\n", ip);
+
+ for (j = 0; he->h_aliases[j] != NULL; j++) {
+ printf("alias: %s\n", he->h_aliases[j]);
+ }
+ }
+ }
+
+ endhostent();
+}
+
+int main(void) {
+ int rc;
+
+ const UnitTest tests[] = {
+ unit_test(test_nwrap_gethostent),
+ };
+
+ rc = run_tests(tests);
+
+ return rc;
+}
commit 93db9fd01cf556c49e4109c5901d4b4886bc1229
Author: Andreas Schneider <asn@samba.org>
AuthorDate: Thu Mar 13 14:58:23 2014 +0100
Commit: Andreas Schneider <asn@samba.org>
CommitDate: Fri Mar 14 11:01:10 2014 +0100
README: Fix prefix env variable name.
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
---
README | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/README b/README
index 3edef91..2ffa564 100644
--- a/README
+++ b/README
@@ -47,4 +47,8 @@ NSS_WRAPPER_MODULE_SO_PATH=/path/to/libnss_yourmodule.so
As each nss module has a special prefix like _nss_winbind_getpwnam() you need
to set the prefix too so nss_wrapper can load the functions with:
-NSS_WRAPPER_MODULE_FN_NAME=<prefix>
+NSS_WRAPPER_MODULE_FN_PREFIX=<prefix>
+
+For _nss_winbind_getpwnam() this would be:
+
+NSS_WRAPPER_MODULE_FN_PREFIX=winbind

View File

@ -1,6 +1,6 @@
Name: nss_wrapper
Version: 1.0.1
Release: 2%{?dist}
Release: 3%{?dist}
License: BSD
Summary: A wrapper for the user, group and hosts NSS API
@ -8,6 +8,8 @@ Url: http://cwrap.org/
Source0: https://ftp.samba.org/pub/cwrap/%{name}-%{version}.tar.gz
Patch0: nss_wrapper-1.0.1-fix_getent_hosts.patch
BuildRequires: cmake
BuildRequires: libcmocka-devel
@ -37,6 +39,8 @@ development/testing.
%prep
%setup -q
%patch0 -p1 -b .nss_wrapper-1.0.1-fix_getent_hosts.patch
%build
if test ! -e "obj"; then
mkdir obj
@ -74,6 +78,9 @@ popd
%{_libdir}/pkgconfig/nss_wrapper.pc
%changelog
* Fri Mar 14 2014 - Andreas Schneider <asn@redhat.com> - 1.0.1-3
- resolves: #1075932 - Fix segfault in 'getent hosts'.
* Tue Feb 11 2014 - Andreas Schneider <asn@redhat.com> - 1.0.1-2
- resolves: #1060906 - Fedora package.
- Remove Group