about summary refs log tree commit diff
path: root/nscd
diff options
context:
space:
mode:
Diffstat (limited to 'nscd')
-rw-r--r--nscd/nscd_getgr_r.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/nscd/nscd_getgr_r.c b/nscd/nscd_getgr_r.c
index eb717056ea..aa9c3fddcc 100644
--- a/nscd/nscd_getgr_r.c
+++ b/nscd/nscd_getgr_r.c
@@ -147,19 +147,20 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
 	 align the pointer.  */
       align = ((__alignof__ (char *) - (p - ((char *) 0)))
 	       & (__alignof__ (char *) - 1));
-      if (buflen < (align + (1 + gr_resp.gr_mem_cnt) * sizeof (char *)
-		    + gr_resp.gr_name_len + gr_resp.gr_passwd_len))
+      total_len = align + (1 + gr_resp.gr_mem_cnt) * sizeof (char *)
+		  + gr_resp.gr_name_len + gr_resp.gr_passwd_len;
+      if (buflen < total_len)
 	{
 	no_room:
 	  __set_errno (ERANGE);
 	  __close (sock);
 	  return ERANGE;
 	}
+      buflen -= total_len;
 
       p += align;
       resultbuf->gr_mem = (char **) p;
       p += (1 + gr_resp.gr_mem_cnt) * sizeof (char *);
-      buflen -= align + (1 + gr_resp.gr_mem_cnt) * sizeof (char *);
 
       /* Set pointers for strings.  */
       resultbuf->gr_name = p;
@@ -180,8 +181,6 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
       vec[1].iov_len = gr_resp.gr_name_len + gr_resp.gr_passwd_len;
       total_len += gr_resp.gr_name_len + gr_resp.gr_passwd_len;
 
-      buflen -= gr_resp.gr_name_len + gr_resp.gr_passwd_len;
-
       /* Get this data.  */
       if (__readv (sock, vec, 2) != total_len)
 	{