diff mbox

nss_nisplus/nisplus-alias.c: fix build warning on gcc7

Message ID 20170524111338.3495-1-ynorov@caviumnetworks.com
State New
Headers show

Commit Message

Yury Norov May 24, 2017, 11:13 a.m. UTC
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(-)

-- 
2.11.0

Comments

Andreas Schwab May 24, 2017, 11:56 a.m. UTC | #1
Please update your sources.

commit f88759ea9b
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Wed Dec 21 23:44:01 2016 +0000

    Fix nss_nisplus build with mainline GCC (bug 20978).

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Yury Norov May 24, 2017, 12:06 p.m. UTC | #2
On Wed, May 24, 2017 at 01:56:43PM +0200, Andreas Schwab wrote:
> Please update your sources.

> 

> commit f88759ea9b

> Author: Joseph Myers <joseph@codesourcery.com>

> Date:   Wed Dec 21 23:44:01 2016 +0000

> 

>     Fix nss_nisplus build with mainline GCC (bug 20978).

> 

> Andreas.


Ah, sorry that. Then forget.
diff mbox

Patch

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);