diff options
author | Jeremy Allison <jra@samba.org> | 2012-04-30 16:24:27 -0700 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2012-06-30 13:43:43 +0200 |
commit | 1896cf4b8bf46436130750f32ebb5d2eecb881d6 (patch) | |
tree | 58c9603ba90b3f24d5f6dd23028dc7da54d1a924 | |
parent | 6d200f4342ce074bbf66ae4e247fcadb95620cf7 (diff) | |
download | samba-1896cf4b8bf46436130750f32ebb5d2eecb881d6.tar.gz |
Fix convert_ss2service() to filter out zero addresses.
(cherry picked from commit 3226be5b5ab771c8cdf98588c40713d36eae4702)
-rw-r--r-- | source3/libsmb/namequery.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index ff43706175f..b68448e16ae 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -848,32 +848,53 @@ struct sockaddr_storage *name_query(int fd, } /******************************************************** - convert an array if struct sockaddr_storage to struct ip_service + Convert an array if struct sockaddr_storage to struct ip_service return false on failure. Port is set to PORT_NONE; + pcount is [in/out] - it is the length of ss_list on input, + and the length of return_iplist on output as we remove any + zero addresses from ss_list. *********************************************************/ static bool convert_ss2service(struct ip_service **return_iplist, const struct sockaddr_storage *ss_list, - int count) + int *pcount) { int i; + int orig_count = *pcount; + int real_count = 0; - if ( count==0 || !ss_list ) + if (orig_count==0 || !ss_list ) return False; + /* Filter out zero addrs. */ + for ( i=0; i<orig_count; i++ ) { + if (is_zero_addr((struct sockaddr *)&ss_list[i])) { + continue; + } + real_count++; + } + if (real_count==0) { + return false; + } + /* copy the ip address; port will be PORT_NONE */ - if ((*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, count)) == + if ((*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, real_count)) == NULL) { DEBUG(0,("convert_ip2service: malloc failed " - "for %d enetries!\n", count )); + "for %d enetries!\n", real_count )); return False; } - for ( i=0; i<count; i++ ) { - (*return_iplist)[i].ss = ss_list[i]; - (*return_iplist)[i].port = PORT_NONE; + for ( i=0, real_count = 0; i<orig_count; i++ ) { + if (is_zero_addr((struct sockaddr *)&ss_list[i])) { + continue; + } + (*return_iplist)[real_count].ss = ss_list[i]; + (*return_iplist)[real_count].port = PORT_NONE; + real_count++; } + *pcount = real_count; return true; } @@ -946,7 +967,7 @@ NTSTATUS name_resolve_bcast(const char *name, success: status = NT_STATUS_OK; - if (!convert_ss2service(return_iplist, ss_list, *return_count) ) + if (!convert_ss2service(return_iplist, ss_list, return_count) ) status = NT_STATUS_INVALID_PARAMETER; SAFE_FREE(ss_list); @@ -1081,7 +1102,7 @@ NTSTATUS resolve_wins(const char *name, success: status = NT_STATUS_OK; - if (!convert_ss2service(return_iplist, ss_list, *return_count)) + if (!convert_ss2service(return_iplist, ss_list, return_count)) status = NT_STATUS_INVALID_PARAMETER; SAFE_FREE(ss_list); |