fix stringop-overflow warning of GCC#201
Conversation
gjasny
left a comment
There was a problem hiding this comment.
Shouldn't the type be something like size_t instead of int?
|
Yes, of course. Fixed. |
|
Is this really a fix? |
|
The original code was fine, there was no bug at all. The PR simply works around a GCC false-positive warning, so silencing a compiler false-positive. |
|
Yeah looking at the original code it's obviously right. But I think either strcpy(aliases[aliascnt], rr_data);or memcpy(aliases[aliascnt], rr_data, rr_data_len);would be better replacements. Mainly because the warning is less likely to come back in the future if GCC starts seeing that aliases[aliascnt] = ares_strdup(rr_data); |
|
@tavianator: I think neither However, your suggestion with |
|
Seeing as strcpy/strncpy/memcpy all do a copy and ares_strdup() returns a pointer, I don't see that as a viable solution without changing the definition and use of 'aliases'. |
|
@RagnarPaulson What? This works for me: diff --git a/ares_parse_ptr_reply.c b/ares_parse_ptr_reply.c
index 29e22cb..54f3a6e 100644
--- a/ares_parse_ptr_reply.c
+++ b/ares_parse_ptr_reply.c
@@ -52,7 +52,6 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
int aliascnt = 0;
int alias_alloc = 8;
char ** aliases;
- size_t rr_data_len;
/* Set *host to NULL for all failure cases. */
*host = NULL;
@@ -125,15 +124,13 @@ int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr,
if (hostname)
ares_free(hostname);
hostname = rr_data;
- rr_data_len = strlen(rr_data)+1;
- aliases[aliascnt] = ares_malloc(rr_data_len * sizeof(char));
+ aliases[aliascnt] = ares_strdup(rr_data);
if (!aliases[aliascnt])
{
ares_free(rr_name);
status = ARES_ENOMEM;
break;
}
- strncpy(aliases[aliascnt], rr_data, rr_data_len);
aliascnt++;
if (aliascnt >= alias_alloc) {
char **ptr; |
|
Yeah, I'm a doofus. I didn't read your comment close enough when you said 'allocation and copy' . Sorry. |
When using a modern GCC to compile c-ares, there is a stringop-overflow warning. This patch simply silences the false-positive warning, there is no actual code flaw. Bug: c-ares#201 Fixed By: Andi Schnebinger @Iniesta8
When using a modern GCC to compile c-ares, there is a stringop-overflow warning as follows:
This patch fixes this issue...