]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/dnssrv.c
Happy New Year
[openldap] / libraries / libldap / dnssrv.c
index 51a711ac67322d8f234792d0f3ccd15229d889c2..1524a3a85df2bb40ce3ab02353a2dfd7c6b30fd1 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2014 The OpenLDAP Foundation.
+ * Copyright 1998-2018 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -361,12 +361,14 @@ int ldap_domain2hostlist(
                hostent_head[hostent_count].priority=priority;
                hostent_head[hostent_count].weight=weight;
                hostent_head[hostent_count].port=port;
-               strncpy(hostent_head[hostent_count].hostname, host, MAXHOST);
+               strncpy(hostent_head[hostent_count].hostname, host, MAXHOST-1);
+               hostent_head[hostent_count].hostname[MAXHOST-1] = '\0';
                hostent_count++;
            }
 add_size:;
            p += size;
        }
+       if (!hostent_head) goto out;
     qsort(hostent_head, hostent_count, sizeof(srv_record), srv_cmp);
 
        if (!srv_seed)
@@ -397,7 +399,7 @@ add_size:;
         if(cur>0){
             hostlist[cur++]=' ';
         }
-        cur += sprintf(&hostlist[cur], "%s:%hd", hostent_head[i].hostname, hostent_head[i].port);
+        cur += sprintf(&hostlist[cur], "%s:%hu", hostent_head[i].hostname, hostent_head[i].port);
     }
     }