about summary refs log tree commit diff
path: root/nss/nss_files/files-XXX.c
diff options
context:
space:
mode:
Diffstat (limited to 'nss/nss_files/files-XXX.c')
-rw-r--r--nss/nss_files/files-XXX.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c
index 40bb7df81e..7291c75d84 100644
--- a/nss/nss_files/files-XXX.c
+++ b/nss/nss_files/files-XXX.c
@@ -102,9 +102,6 @@ internal_endent (void)
       fclose (stream);
       stream = NULL;
     }
-
-  /* Reset STAYOPEN flag.  */
-  keep_stream = 0;
 }
 
 
@@ -116,6 +113,9 @@ CONCAT(_nss_files_end,ENTNAME) (void)
 
   internal_endent ();
 
+  /* Reset STAYOPEN flag.  */
+  keep_stream = 0;
+
   __libc_lock_unlock (lock);
 
   return NSS_STATUS_SUCCESS;
@@ -131,15 +131,17 @@ internal_getent (struct STRUCTURE *result,
   struct parser_data *data = (void *) buffer;
   int linebuflen = buffer + buflen - data->linebuffer;
 
-  /* Someone called internal_setent before calling us, so if the
-     stream is not open now the file could not be opened.  */
+  /* Be prepared that the set*ent function was not called before.  */
   if (stream == NULL)
     {
-      H_ERRNO_SET (NETDB_INTERNAL);
-      return NSS_STATUS_UNAVAIL;
+      enum nss_status status;
+
+      status = internal_setent (0);
+      if (status != NSS_STATUS_SUCCESS)
+	return status;
     }
 
-  if (buflen < sizeof *data + 1)
+  if (buflen < (int) sizeof *data + 1)
     {
       errno = ERANGE;
       return NSS_STATUS_NOTFOUND;
@@ -155,6 +157,9 @@ internal_getent (struct STRUCTURE *result,
 	  return NSS_STATUS_NOTFOUND;
 	}
 
+      /* Terminate the line for any case.  */
+      data->linebuffer[linebuflen - 1] = '\0';
+
       /* Skip leading blanks.  */
       while (isspace (*p))
 	++p;