summaryrefslogtreecommitdiff
path: root/grp/putgrent.c
diff options
context:
space:
mode:
Diffstat (limited to 'grp/putgrent.c')
-rw-r--r--grp/putgrent.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/grp/putgrent.c b/grp/putgrent.c
index e4d662c6b5..4442b27311 100644
--- a/grp/putgrent.c
+++ b/grp/putgrent.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -16,7 +16,9 @@
<http://www.gnu.org/licenses/>. */
#include <errno.h>
+#include <nss.h>
#include <stdio.h>
+#include <string.h>
#include <grp.h>
#define flockfile(s) _IO_flockfile (s)
@@ -27,13 +29,14 @@
/* Write an entry to the given stream.
This must know the format of the group file. */
int
-putgrent (gr, stream)
- const struct group *gr;
- FILE *stream;
+putgrent (const struct group *gr, FILE *stream)
{
int retval;
- if (__glibc_unlikely (gr == NULL) || __glibc_unlikely (stream == NULL))
+ if (__glibc_unlikely (gr == NULL) || __glibc_unlikely (stream == NULL)
+ || gr->gr_name == NULL || !__nss_valid_field (gr->gr_name)
+ || !__nss_valid_field (gr->gr_passwd)
+ || !__nss_valid_list_field (gr->gr_mem))
{
__set_errno (EINVAL);
return -1;
@@ -56,9 +59,7 @@ putgrent (gr, stream)
if (gr->gr_mem != NULL)
{
- int i;
-
- for (i = 0 ; gr->gr_mem[i] != NULL; i++)
+ for (size_t i = 0; gr->gr_mem[i] != NULL; i++)
if (fprintf (stream, i == 0 ? "%s" : ",%s", gr->gr_mem[i]) < 0)
{
/* What else can we do? */