SonarCloud: Fix additional code smells

Fix By: Brad House (@bradh352)
pull/580/head
Brad House 1 year ago
parent b8c6a818aa
commit 8890366609
  1. 12
      sonar-project.properties
  2. 4
      src/lib/ares_getaddrinfo.c
  3. 26
      src/tools/adig.c

@ -16,8 +16,18 @@ sonar.exclusions=test/
sonar.sourceEncoding=UTF-8
sonar.issue.ignore.multicriteria=m1
sonar.issue.ignore.multicriteria=m1,m2,m3
# c:S5955 Loop variables should be declared in the minimal possible scope
# Not possible in C89
sonar.issue.ignore.multicriteria.m1.ruleKey=c:S5955
sonar.issue.ignore.multicriteria.m1.resourceKey=**/*
# c:S924 Reduce the number of nested "goto" statements from 2 to 1 authorized.
# This is a common practice in error handling, don't understand this recommendation.
sonar.issue.ignore.multicriteria.m2.ruleKey=c:S924
sonar.issue.ignore.multicriteria.m2.resourceKey=**/*
# php:S105 Tabulation characters should not be used
# Required for MSVC Makefiles
sonar.issue.ignore.multicriteria.m3.ruleKey=php:S105
sonar.issue.ignore.multicriteria.m3.resourceKey=**/Makefile.inc

@ -863,7 +863,7 @@ static ares_bool_t as_is_first(const struct host_query* hquery)
ndots++;
}
}
if (nname && hquery->name[nname-1] == '.')
if (hquery->name != NULL && nname && hquery->name[nname-1] == '.')
{
/* prevent ARES_EBADNAME for valid FQDN, where ndots < channel->ndots */
return ARES_TRUE;
@ -874,7 +874,7 @@ static ares_bool_t as_is_first(const struct host_query* hquery)
static ares_bool_t as_is_only(const struct host_query* hquery)
{
size_t nname = ares_strlen(hquery->name);
if (nname && hquery->name[nname-1] == '.')
if (hquery->name != NULL && nname && hquery->name[nname-1] == '.')
return ARES_TRUE;
return ARES_FALSE;
}

@ -166,6 +166,28 @@ static void append_addr_list(struct ares_addr_node **head,
struct ares_addr_node *node);
static void print_help_info_adig(void);
static size_t ares_strcpy(char *dest, const char *src, size_t dest_size)
{
size_t len = 0;
if (dest == NULL || dest_size == 0)
return 0;
if (src != NULL)
len = strlen(src);
if (len >= dest_size)
len = dest_size - 1;
if (len) {
memcpy(dest, src, len);
}
dest[len] = 0;
return len;
}
int main(int argc, char **argv)
{
ares_channel channel;
@ -893,7 +915,7 @@ static int convert_query (char **name_p, int use_bitstring)
*c++ = hex_chars [lo];
*c++ = hex_chars [hi];
}
strcpy (c, "].IP6.ARPA");
ares_strcpy (c, "].IP6.ARPA", sizeof(new_name) - strlen(c));
}
else
{
@ -906,7 +928,7 @@ static int convert_query (char **name_p, int use_bitstring)
*c++ = hex_chars [hi];
*c++ = '.';
}
strcpy (c, "IP6.ARPA");
ares_strcpy (c, "IP6.ARPA", sizeof(new_name) - strlen(c));
}
*name_p = new_name;
return (1);

Loading…
Cancel
Save