detect/iprep: fix loading of mixed ipv4/ipv6 lists

Improper reuse of the address data structure between loading
different lines in the iprep file would lead to the host using
a malformed address.
pull/5855/head
Victor Julien 5 years ago
parent 82ecf64fe6
commit 7b03e6837e

@ -431,9 +431,6 @@ static int SRepLoadFile(SRepCIDRTree *cidr_ctx, char *filename)
int SRepLoadFileFromFD(SRepCIDRTree *cidr_ctx, FILE *fp) int SRepLoadFileFromFD(SRepCIDRTree *cidr_ctx, FILE *fp)
{ {
char line[8192] = ""; char line[8192] = "";
Address a;
memset(&a, 0x00, sizeof(a));
a.family = AF_INET;
while(fgets(line, (int)sizeof(line), fp) != NULL) { while(fgets(line, (int)sizeof(line), fp) != NULL) {
size_t len = strlen(line); size_t len = strlen(line);
@ -455,6 +452,10 @@ int SRepLoadFileFromFD(SRepCIDRTree *cidr_ctx, FILE *fp)
line[len - 1] = '\0'; line[len - 1] = '\0';
} }
Address a;
memset(&a, 0x00, sizeof(a));
a.family = AF_INET;
uint8_t cat = 0, value = 0; uint8_t cat = 0, value = 0;
int r = SRepSplitLine(cidr_ctx, line, &a, &cat, &value); int r = SRepSplitLine(cidr_ctx, line, &a, &cat, &value);
if (r < 0) { if (r < 0) {

Loading…
Cancel
Save