lib:socket: Return early if we have only one interface
[samba.git] / lib / socket / interfaces.c
index dacd1180fa75b86bb9939cf294d608621f05161d..168bff501c213b98aa89f462144d36d36286cfca 100644 (file)
@@ -146,7 +146,7 @@ static void query_iface_speed_from_name(const char *name, uint64_t *speed)
        }
 
        ZERO_STRUCT(ifr);
-       strncpy(ifr.ifr_name, name, IF_NAMESIZE);
+       strlcpy(ifr.ifr_name, name, IF_NAMESIZE);
 
        ifr.ifr_data = (void *)&edata;
        edata.cmd = ETHTOOL_GLINK;
@@ -367,7 +367,10 @@ int get_interfaces(TALLOC_CTX *mem_ctx, struct iface_struct **pifaces)
        int total, i, j;
 
        total = _get_interfaces(mem_ctx, &ifaces);
-       if (total <= 0) return total;
+       /* If we have an error, no interface or just one we can leave */
+       if (total <= 1) {
+               return total;
+       }
 
        /* now we need to remove duplicates */
        TYPESAFE_QSORT(ifaces, total, iface_comp);