Back-port fix for bug found by kukks - Samba adding
[samba.git] / source / nmbd / nmbd_namelistdb.c
index d71eb5479a293b98889eb095a46ec640692dfe47..cda12885ef4e4d33660206a4eb1217251552bc6e 100644 (file)
@@ -505,8 +505,12 @@ void add_samba_names_to_subnet( struct subnet_record *subrec )
                        return;
                }
 
-               for( bcast_subrecs = FIRST_SUBNET, i = 0; bcast_subrecs; bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++ )
+               for( bcast_subrecs = FIRST_SUBNET, i = 0; bcast_subrecs &&
+                               i < num_ips;
+                               bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++ ) {
                        iplist[i] = bcast_subrecs->myip;
+               }
+               num_ips = i;
        }
 
        add_name_to_subnet(subrec,"*",0x0,samba_nb_type, PERMANENT_TTL,