[asterisk-commits] file: branch group/dns_srv r433305 - /team/group/dns_srv/main/dns_srv.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Mar 23 10:51:32 CDT 2015
Author: file
Date: Mon Mar 23 10:51:30 2015
New Revision: 433305
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433305
Log:
Use the approach srv.c uses for enforcing limits and interpreting the SRV record.
Modified:
team/group/dns_srv/main/dns_srv.c
Modified: team/group/dns_srv/main/dns_srv.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_srv/main/dns_srv.c?view=diff&rev=433305&r1=433304&r2=433305
==============================================================================
--- team/group/dns_srv/main/dns_srv.c (original)
+++ team/group/dns_srv/main/dns_srv.c Mon Mar 23 10:51:30 2015
@@ -43,17 +43,22 @@
struct ast_dns_record *ast_dns_srv_alloc(struct ast_dns_query *query, const char *data, const size_t size)
{
+ struct srv {
+ uint16_t priority;
+ uint16_t weight;
+ uint16_t port;
+ } __attribute__((__packed__)) *srv_record;
const char *ptr;
char *srv_offset;
char *srv_search_base = (char *)query->result->answer;
size_t remaining_size = query->result->answer_size;
- size_t remaining = size;
struct ast_dns_srv_record *srv;
- uint16_t priority;
- uint16_t weight;
- uint16_t port;
int host_size;
char host[NI_MAXHOST] = "";
+
+ if (size < sizeof(*srv_record)) {
+ return NULL;
+ }
while (1) {
srv_offset = memchr(srv_search_base, data[0], remaining_size);
@@ -72,25 +77,8 @@
ast_assert(ptr != NULL);
- if (remaining < 2) {
- return NULL;
- }
- priority = (ptr[1] << 0) | (ptr[0] << 8);
- ptr += 2;
- remaining -= 2;
-
- if (remaining < 2) {
- return NULL;
- }
- weight = (ptr[1] << 0) | (ptr[0] << 8);
- ptr += 2;
- remaining -= 2;
-
- if (remaining < 2) {
- return NULL;
- }
- port = (ptr[1] << 0) | (ptr[0] << 8);
- ptr += 2;
+ srv_record = (struct srv *)ptr;
+ ptr += sizeof(*srv_record);
host_size = dn_expand((unsigned char *)query->result->answer, (unsigned char *) (srv_offset + size), (unsigned char *) ptr, host, sizeof(host) - 1);
if (host_size < 0) {
@@ -107,9 +95,9 @@
return NULL;
}
- srv->priority = priority;
- srv->weight = weight;
- srv->port = port;
+ srv->priority = ntohs(srv_record->priority);
+ srv->weight = ntohs(srv_record->weight);
+ srv->port = ntohs(srv_record->port);
srv->host = srv->data + size;
strcpy((char *)srv->host, host); /* SAFE */
More information about the asterisk-commits
mailing list