Fix invalid strncpy use (#1675450)

Produces error on latest gcc.
This commit is contained in:
Petr Menšík 2019-02-18 21:08:14 +01:00
parent 74a0fd925c
commit f11f166fd2
2 changed files with 34 additions and 1 deletions

View File

@ -0,0 +1,29 @@
From 08800e61eaba05265d3d976b0e9922f9bc4c63b2 Mon Sep 17 00:00:00 2001
From: Petr Mensik <pemensik@redhat.com>
Date: Mon, 18 Feb 2019 20:27:18 +0100
Subject: [PATCH] Always produce zero terminated address
---
lib/backend.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/backend.c b/lib/backend.c
index 1b3dadc..b895651 100644
--- a/lib/backend.c
+++ b/lib/backend.c
@@ -287,8 +287,10 @@ netresolve_backend_add_path(netresolve_query_t query,
if (length)
memcpy(path.node.address, address, length);
- else
- strncpy(path.node.address, address, sizeof path.node.address);
+ else {
+ path.node.address[sizeof(path.node.address)-1] = 0;
+ strncpy(path.node.address, address, sizeof(path.node.address)-1);
+ }
if (query->request.servname && (!socktype || !protocol || !port)) {
struct path_data data = { .query = query, .path = &path };
--
2.20.1

View File

@ -2,7 +2,7 @@
Name: netresolve
Version: 0.0.1
Release: 0.23%{?snapshot_suffix}%{?dist}
Release: 0.24%{?snapshot_suffix}%{?dist}
Summary: Generic name resolution library
License: BSD
# https://github.com/crossdistro/netresolve , possibly?
@ -11,6 +11,7 @@ Source0: %{name}-0.0.1.tar.xz
# Fix a syntax error in a test
# From https://github.com/crossdistro/netresolve/pull/2
Patch0: netresolve-0.0.1-test-equality.patch
Patch1: netresolve-0.0.1-strncpy.patch
BuildRequires: ldns-devel
BuildRequires: pkgconfig(libcares)
@ -233,6 +234,9 @@ make check || { cat ./test-suite.log; false; }
%{_libdir}/libnss_netresolve.so
%changelog
* Tue Feb 19 2019 Petr Menšík <pemensik@redhat.com> - 0.0.1-0.24.20160317git
- Fix build under new gcc (#1675450)
* Fri Feb 01 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.0.1-0.23.20160317git
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild