From: Joshua Colp Date: Tue, 7 Feb 2017 18:01:03 +0000 (+0000) Subject: srv: Fix crash when ast_srv_lookup is used and 0 records are returned. X-Git-Tag: 13.15.0-rc1~101^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e14e086cf6e9b18ab2629e0acbfa1fb206bbb48;p=thirdparty%2Fasterisk.git srv: Fix crash when ast_srv_lookup is used and 0 records are returned. When performing an SRV lookup using the ast_srv_lookup function it did not properly handle the situation where 0 records are returned. If this happened it would wrongly assume that at least one record was present. This change fixes the code so it will exit early if an error occurs or if 0 records are returned. ASTERISK-26772 patches: srv_lookup.patch submitted by nappsoft (license 6822) Change-Id: I09b19081c74e0ad11c12bf54a257243b1bcb2351 --- diff --git a/main/srv.c b/main/srv.c index 0938a0c036..dcfcc2b6ce 100644 --- a/main/srv.c +++ b/main/srv.c @@ -211,7 +211,8 @@ int ast_srv_lookup(struct srv_context **context, const char *service, const char } AST_LIST_HEAD_INIT_NOLOCK(&(*context)->entries); - if ((ast_search_dns(*context, service, C_IN, T_SRV, srv_callback)) < 0) { + if (((ast_search_dns(*context, service, C_IN, T_SRV, srv_callback)) < 1) || + AST_LIST_EMPTY(&(*context)->entries)) { ast_free(*context); *context = NULL; return -1;