Skip to content

Commit

Permalink
influxdbc: copy with buffer size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Mar 1, 2024
1 parent 181c602 commit 73c6615
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/modules/influxdbc/ic.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,32 @@ void ic_influx_database(char *host, long port,

he = gethostbyname(host);
if(he == NULL) {
sprintf(errorbuf,
snprintf(errorbuf, 1024,
"influx host=%s to ip address convertion failed "
"gethostbyname(), bailing out\n",
host);
error(errorbuf);
}
/* this could return multiple ip addresses but we assume its the first one */
if(he->h_addr_list[0] != NULL) {
strcpy(influx_ip,
inet_ntoa(*(struct in_addr *)(he->h_addr_list[0])));
strncpy(influx_ip,
inet_ntoa(*(struct in_addr *)(he->h_addr_list[0])), 16);
influx_ip[16] = '\0';
DEBUG fprintf(stderr,
"ic_influx_by_hostname hostname=%s converted to ip "
"address %s))\n",
host, influx_ip);
} else {
sprintf(errorbuf,
snprintf(errorbuf, 1024,
"influx host=%s to ip address convertion failed (empty "
"list), bailing out\n",
host);
error(errorbuf);
}
} else {
strcpy(influx_ip,
host); /* perhaps the hostname is actually an ip address */
strncpy(influx_ip, host,
16); /* perhaps the hostname is actually an ip address */
influx_ip[16] = '\0';
}
}
}
Expand Down Expand Up @@ -338,7 +340,7 @@ void ic_push()
}
for(i = 0; i < 1024; i++) /* empty the buffer */
result[i] = 0;
if((ret = read(sockfd, result, sizeof(result))) > 0) {
if((ret = read(sockfd, result, sizeof(result) - 1)) > 0) {
result[ret] = 0;
DEBUG fprintf(
stderr, "received bytes=%d data=<%s>\n", ret, result);
Expand Down

0 comments on commit 73c6615

Please sign in to comment.