This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] nss_nisplus/nisplus-alias.c: fix build warning on gcc7
- From: Yury Norov <ynorov at caviumnetworks dot com>
- To: libc-alpha at sourceware dot org
- Cc: Yury Norov <ynorov at caviumnetworks dot com>
- Date: Wed, 24 May 2017 14:13:38 +0300
- Subject: [PATCH] nss_nisplus/nisplus-alias.c: fix build warning on gcc7
- Authentication-results: sourceware.org; auth=none
- Authentication-results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=caviumnetworks.com;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
Hi all,
gcc7 for arm64 warns about NULL pointer passed to strlen() and
snprintf() in _nss_nisplus_getaliasbyname_r(). If Werror is enabled,
it is treaded as error, and so breask build:
nss_nisplus/nisplus-alias.c: In function
‘_nss_nisplus_getaliasbyname_r’:
nss_nisplus/nisplus-alias.c:300:12: error: argument 1 null where
non-null expected [-Werror=nonnull]
char buf[strlen (name) + 9 + tablename_len];
^~~~~~~~~~~~~
In file included from ../include/string.h:54:0,
from nss_nisplus/nisplus-alias.c:23:
../string/string.h:394:15: note: in a call to function ‘strlen’ declared here
extern size_t strlen (const char *__s)
^~~~~~
nss_nisplus/nisplus-alias.c:303:39: error: ‘%s’ directive argument is null [-Werror=format-truncation=]
snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
^~
cc1: all warnings being treated as errors
* nis/nss_nisplus/nisplus-alias.c: don't pass name variable
known to be NULL to strlen() and snprintf() in
_nss_nisplus_getaliasbyname_r()
If the line "[name=],..." looks weird, I'll resend the patch, if someone will
hint me how it should look. Anyway, I think that it currently should look like
this.
Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
nis/nss_nisplus/nisplus-alias.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c
index 7f698b4e6d..509ace1f83 100644
--- a/nis/nss_nisplus/nisplus-alias.c
+++ b/nis/nss_nisplus/nisplus-alias.c
@@ -297,10 +297,10 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
return NSS_STATUS_UNAVAIL;
}
- char buf[strlen (name) + 9 + tablename_len];
+ char buf[tablename_len + 9];
int olderr = errno;
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
+ snprintf (buf, sizeof (buf), "[name=],%s", tablename_val);
nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
--
2.11.0