diff options
author | Yu Jiung <jiung.yu@samsung.com> | 2016-11-10 16:24:08 +0900 |
---|---|---|
committer | Yu Jiung <jiung.yu@samsung.com> | 2016-11-10 16:25:02 +0900 |
commit | 8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8 (patch) | |
tree | 81f0750d91aa467df3ee81cf30d22a65db2e6685 /ares_getnameinfo.c | |
parent | ccccebb78520ec3a26a18370936516b12ae5d53a (diff) | |
parent | 45e88a8337839e5fd88519bc55467053d521c9f6 (diff) | |
download | c-ares-8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8.tar.gz c-ares-8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8.tar.bz2 c-ares-8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8.zip |
Merge branch 'tizen' into tizen_basetizen_4.0.m2_releasetizen_4.0.IoT.p1_releasesubmit/tizen_base/20170705.023439submit/tizen_base/20170703.013654submit/tizen_4.0_base/20170828.000001submit/tizen_4.0_base/20170828.000000submit/tizen_4.0_base/20170811.071500accepted/tizen/base/20170707.183634accepted/tizen/4.0/base/20170828.221324accepted/tizen/4.0/base/20170811.093019
Conflicts:
packaging/c-ares.spec
Change-Id: I1ec10e394aed3ef19ee21fefbe3aba7d7a615c74
Diffstat (limited to 'ares_getnameinfo.c')
-rw-r--r-- | ares_getnameinfo.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/ares_getnameinfo.c b/ares_getnameinfo.c index 5b9f638..4516112 100644 --- a/ares_getnameinfo.c +++ b/ares_getnameinfo.c @@ -77,7 +77,7 @@ static char *lookup_service(unsigned short port, int flags, static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int scopeid, char *buf, size_t buflen); #endif -static char *ares_striendstr(const char *s1, const char *s2); +STATIC_TESTABLE char *ares_striendstr(const char *s1, const char *s2); void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa, ares_socklen_t salen, @@ -163,7 +163,7 @@ void ares_getnameinfo(ares_channel channel, const struct sockaddr *sa, /* This is where a DNS lookup becomes necessary */ else { - niquery = malloc(sizeof(struct nameinfo_query)); + niquery = ares_malloc(sizeof(struct nameinfo_query)); if (!niquery) { callback(arg, ARES_ENOMEM, 0, NULL, NULL); @@ -234,7 +234,7 @@ static void nameinfo_callback(void *arg, int status, int timeouts, niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, (char *)(host->h_name), service); - free(niquery); + ares_free(niquery); return; } /* We couldn't find the host, but it's OK, we can use the IP */ @@ -265,11 +265,11 @@ static void nameinfo_callback(void *arg, int status, int timeouts, } niquery->callback(niquery->arg, ARES_SUCCESS, niquery->timeouts, ipbuf, service); - free(niquery); + ares_free(niquery); return; } niquery->callback(niquery->arg, status, niquery->timeouts, NULL, NULL); - free(niquery); + ares_free(niquery); } static char *lookup_service(unsigned short port, int flags, @@ -281,6 +281,8 @@ static char *lookup_service(unsigned short port, int flags, struct servent se; #endif char tmpbuf[4096]; + char *name; + size_t name_len; if (port) { @@ -297,12 +299,13 @@ static char *lookup_service(unsigned short port, int flags, else proto = "tcp"; #ifdef HAVE_GETSERVBYPORT_R + memset(&se, 0, sizeof(se)); sep = &se; memset(tmpbuf, 0, sizeof(tmpbuf)); #if GETSERVBYPORT_R_ARGS == 6 if (getservbyport_r(port, proto, &se, (void *)tmpbuf, sizeof(tmpbuf), &sep) != 0) - sep = NULL; + sep = NULL; /* LCOV_EXCL_LINE: buffer large so this never fails */ #elif GETSERVBYPORT_R_ARGS == 5 sep = getservbyport_r(port, proto, &se, (void *)tmpbuf, sizeof(tmpbuf)); @@ -323,17 +326,23 @@ static char *lookup_service(unsigned short port, int flags, #endif } if (sep && sep->s_name) - /* get service name */ - strcpy(tmpbuf, sep->s_name); + { + /* get service name */ + name = sep->s_name; + } else - /* get port as a string */ - sprintf(tmpbuf, "%u", (unsigned int)ntohs(port)); - if (strlen(tmpbuf) < buflen) + { + /* get port as a string */ + sprintf(tmpbuf, "%u", (unsigned int)ntohs(port)); + name = tmpbuf; + } + name_len = strlen(name); + if (name_len < buflen) /* return it if buffer big enough */ - strcpy(buf, tmpbuf); + memcpy(buf, name, name_len + 1); else /* avoid reusing previous one */ - buf[0] = '\0'; + buf[0] = '\0'; /* LCOV_EXCL_LINE: no real service names are too big */ return buf; } buf[0] = '\0'; @@ -383,7 +392,7 @@ static void append_scopeid(struct sockaddr_in6 *addr6, unsigned int flags, #endif /* Determines if s1 ends with the string in s2 (case-insensitive) */ -static char *ares_striendstr(const char *s1, const char *s2) +STATIC_TESTABLE char *ares_striendstr(const char *s1, const char *s2) { const char *c1, *c2, *c1_begin; int lo1, lo2; @@ -409,7 +418,5 @@ static char *ares_striendstr(const char *s1, const char *s2) c2++; } } - if (c2 == c1 && c2 == NULL) - return (char *)c1_begin; - return NULL; + return (char *)c1_begin; } |