about summary refs log tree commit diff
path: root/hesiod
diff options
context:
space:
mode:
Diffstat (limited to 'hesiod')
-rw-r--r--hesiod/nss_hesiod/hesiod-grp.c20
-rw-r--r--hesiod/nss_hesiod/hesiod-pwd.c20
-rw-r--r--hesiod/nss_hesiod/hesiod-service.c16
3 files changed, 31 insertions, 25 deletions
diff --git a/hesiod/nss_hesiod/hesiod-grp.c b/hesiod/nss_hesiod/hesiod-grp.c
index 7b0832dbe3..e08b9dca8c 100644
--- a/hesiod/nss_hesiod/hesiod-grp.c
+++ b/hesiod/nss_hesiod/hesiod-grp.c
@@ -81,13 +81,14 @@ _nss_hesiod_endgrent (void)
 
 static enum nss_status
 lookup (const char *name, const char *type, struct group *grp,
-	char *buffer, size_t buflen)
+	char *buffer, size_t buflen, int *errnop)
 {
   enum nss_status status;
   struct parser_data *data = (void *) buffer;
   size_t linebuflen;
   char **list;
   int parse_res;
+  size_t len;
 
   status = internal_setgrent ();
   if (status != NSS_STATUS_SUCCESS)
@@ -98,17 +99,18 @@ lookup (const char *name, const char *type, struct group *grp,
     return errno == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
 
   linebuflen = buffer + buflen - data->linebuffer;
-  if (linebuflen < strlen (*list) + 1)
+  len = strlen (*list) + 1;
+  if (linebuflen < len)
     {
       hesiod_free_list (context, list);
-      __set_errno (ERANGE);
+      *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  strcpy (buffer, *list);
+  memcpy (data->linebuffer, *list, len);
   hesiod_free_list (context, list);
 
-  parse_res = _nss_files_parse_grent (buffer, grp, data, buflen);
+  parse_res = _nss_files_parse_grent (buffer, grp, data, buflen, errnop);
   if (parse_res < 1)
     return parse_res == -1 ? NSS_STATUS_TRYAGAIN : NSS_STATUS_NOTFOUND;
 
@@ -117,13 +119,13 @@ lookup (const char *name, const char *type, struct group *grp,
 
 enum nss_status
 _nss_hesiod_getgrnam_r (const char *name, struct group *grp,
-			char *buffer, size_t buflen)
+			char *buffer, size_t buflen, int *errnop)
 {
   enum nss_status status;
 
   __libc_lock_lock (lock);
 
-  status = lookup (name, "group", grp, buffer, buflen);
+  status = lookup (name, "group", grp, buffer, buflen, errnop);
 
   __libc_lock_unlock (lock);
 
@@ -132,7 +134,7 @@ _nss_hesiod_getgrnam_r (const char *name, struct group *grp,
 
 enum nss_status
 _nss_hesiod_getgrgid_r (gid_t gid, struct group *grp,
-			char *buffer, size_t buflen)
+			char *buffer, size_t buflen, int *errnop)
 {
   enum nss_status status = NSS_STATUS_UNAVAIL;
   char gidstr[21];	/* We will probably never have a gid_t with more
@@ -142,7 +144,7 @@ _nss_hesiod_getgrgid_r (gid_t gid, struct group *grp,
 
   __libc_lock_lock (lock);
 
-  status = lookup (gidstr, "gid", grp, buffer, buflen);
+  status = lookup (gidstr, "gid", grp, buffer, buflen, errnop);
 
   __libc_lock_unlock (lock);
 
diff --git a/hesiod/nss_hesiod/hesiod-pwd.c b/hesiod/nss_hesiod/hesiod-pwd.c
index bb2a4c8785..ce97443164 100644
--- a/hesiod/nss_hesiod/hesiod-pwd.c
+++ b/hesiod/nss_hesiod/hesiod-pwd.c
@@ -81,13 +81,14 @@ _nss_hesiod_endpwent (void)
 
 static enum nss_status
 lookup (const char *name, const char *type, struct passwd *pwd,
-	char *buffer, size_t buflen)
+	char *buffer, size_t buflen, int *errnop)
 {
   enum nss_status status;
   struct parser_data *data = (void *) buffer;
   size_t linebuflen;
   char **list;
   int parse_res;
+  size_t len;
 
   status = internal_setpwent ();
   if (status != NSS_STATUS_SUCCESS)
@@ -98,17 +99,18 @@ lookup (const char *name, const char *type, struct passwd *pwd,
     return errno == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
 
   linebuflen = buffer + buflen - data->linebuffer;
-  if (linebuflen < strlen (*list) + 1)
+  len = strlen (*list) + 1;
+  if (linebuflen < len)
     {
       hesiod_free_list (context, list);
-      __set_errno (ERANGE);
+      *errnop = ERANGE;
       return NSS_STATUS_TRYAGAIN;
     }
 
-  strcpy (data->linebuffer, *list);
+  memcpy (data->linebuffer, *list, len);
   hesiod_free_list (context, list);
 
-  parse_res = _nss_files_parse_pwent (buffer, pwd, data, buflen);
+  parse_res = _nss_files_parse_pwent (buffer, pwd, data, buflen, errnop);
   if (parse_res < 1)
     return parse_res == -1 ? NSS_STATUS_TRYAGAIN : NSS_STATUS_NOTFOUND;
 
@@ -117,13 +119,13 @@ lookup (const char *name, const char *type, struct passwd *pwd,
 
 enum nss_status
 _nss_hesiod_getpwnam_r (const char *name, struct passwd *pwd,
-			char *buffer, size_t buflen)
+			char *buffer, size_t buflen, int *errnop)
 {
   enum nss_status status;
 
   __libc_lock_lock (lock);
 
-  status = lookup (name, "passwd", pwd, buffer, buflen);
+  status = lookup (name, "passwd", pwd, buffer, buflen, errnop);
 
   __libc_lock_unlock (lock);
 
@@ -132,7 +134,7 @@ _nss_hesiod_getpwnam_r (const char *name, struct passwd *pwd,
 
 enum nss_status
 _nss_hesiod_getpwuid_r (uid_t uid, struct passwd *pwd,
-			char *buffer, size_t buflen)
+			char *buffer, size_t buflen, int *errnop)
 {
   enum nss_status status = NSS_STATUS_UNAVAIL;
   char uidstr[21];	/* We will probably never have a gid_t with more
@@ -142,7 +144,7 @@ _nss_hesiod_getpwuid_r (uid_t uid, struct passwd *pwd,
 
   __libc_lock_lock (lock);
 
-  status = lookup (uidstr, "uid", pwd, buffer, buflen);
+  status = lookup (uidstr, "uid", pwd, buffer, buflen, errnop);
 
   __libc_lock_unlock (lock);
 
diff --git a/hesiod/nss_hesiod/hesiod-service.c b/hesiod/nss_hesiod/hesiod-service.c
index f74877f748..e0ca965310 100644
--- a/hesiod/nss_hesiod/hesiod-service.c
+++ b/hesiod/nss_hesiod/hesiod-service.c
@@ -97,7 +97,7 @@ _nss_hesiod_endservent (void)
 
 static enum nss_status
 lookup (const char *name, const char *protocol, struct servent *serv,
-	char *buffer, size_t buflen)
+	char *buffer, size_t buflen, int *errnop)
 {
   enum nss_status status;
   struct parser_data *data = (void *) buffer;
@@ -120,16 +120,18 @@ lookup (const char *name, const char *protocol, struct servent *serv,
   found = 0;
   do
     {
-      if (linebuflen < strlen (*item) + 1)
+      size_t len = strlen (*item) + 1;
+
+      if (linebuflen < len)
 	{
 	  hesiod_free_list (context, list);
-	  __set_errno (ERANGE);
+	  *errnop = ERANGE;
 	  return NSS_STATUS_TRYAGAIN;
 	}
 
-      strcpy (data->linebuffer, *item);
+      memcpy (data->linebuffer, *item, len);
 
-      parse_res = parse_line (buffer, serv, data, buflen);
+      parse_res = parse_line (buffer, serv, data, buflen, errnop);
       if (parse_res == -1)
 	{
 	  hesiod_free_list (context, list);
@@ -151,13 +153,13 @@ lookup (const char *name, const char *protocol, struct servent *serv,
 enum nss_status
 _nss_hesiod_getservbyname_r (const char *name, const char *protocol,
 			     struct servent *serv,
-			     char *buffer, size_t buflen)
+			     char *buffer, size_t buflen, int *errnop)
 {
   enum nss_status status;
 
   __libc_lock_lock (lock);
 
-  status = lookup (name, protocol, serv, buffer, buflen);
+  status = lookup (name, protocol, serv, buffer, buflen, errnop);
 
   __libc_lock_unlock (lock);