From 74b86b1190642a4dcad4cb2b587e26c0d4d56725 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Wed, 16 Jul 2025 11:03:12 -0400 Subject: [PATCH] IP to be relayed file is properly scanned --- lib/subafn.c | 37 +++++++++++++++++++++++++++++++++++-- lib/subafn.h | 3 +++ lib/unieml.c | 10 +++++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/subafn.c b/lib/subafn.c index 50d16e9..eeb856a 100644 --- a/lib/subafn.c +++ b/lib/subafn.c @@ -15,6 +15,7 @@ #include "subafn.h" +#define AFT sizeof(struct in6_addr) /* */ @@ -159,6 +160,38 @@ return afnnum; */ /********************************************************/ /* */ +/* Procedure to set IPNUM mask. */ +/* */ +/********************************************************/ +PUBLIC AFNTYP *afn_maskip(AFNTYP *afnnum,int cidr) + +{ +if (afnnum!=(AFNTYP *)0) { + unsigned int num; + int mxcidr; + + mxcidr=32; + if (afnnum->afntype==AF_INET6) + mxcidr=128; + if (cidr>mxcidr) + cidr=mxcidr; + afnnum->afnmask=cidr; + num=cidr/8; + cidr%=8; + if (cidr!=0) { + afnnum->ip[num]&=(~0U<<(8-cidr)); + num++; + } + if (numip+num,'\000',AFT-num); + } +return afnnum; +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to return a string with */ /* ipnum address and MASK in clear format */ /* Address need to freed. */ @@ -291,7 +324,7 @@ while (proceed==true) { afnnum=(AFNTYP *)calloc(1,sizeof(AFNTYP)); afnnum->afntype=AF_INET; afnnum->afnmask=32; - if (strchr(oneipstr,'|')==(char *)0) + if (strchr(oneipstr,':')==(char *)0) phase++; //This is an IPV4 number break; case 1 : //IP is an IPV6 format @@ -326,7 +359,7 @@ while (proceed==true) { break; case 3 : //lets convert it afnnum->strnumip=afn_getstrip(afnnum); - //(void) printf("JMPDBG <%s> -> to <%s>\n", onecleanipstr,afnnum->strnumip); + //(void) printf("JMPDBG <%s> -> to <%s>\n",oneipstr,afnnum->strnumip); break; default : /*SAFE guard */ proceed=false; diff --git a/lib/subafn.h b/lib/subafn.h index f19a494..3b06623 100644 --- a/lib/subafn.h +++ b/lib/subafn.h @@ -33,6 +33,9 @@ typedef struct { //procedure to free memory used by an AFNTYP structure extern AFNTYP *afn_freeipnum(AFNTYP *afnnum); +//procedure to set IPNUM mask +extern AFNTYP *afn_maskip(AFNTYP *afnnum,int cidr); + //procedure to convert a AFNTYP structure to an standardised //IP number extern char *afn_stripnum(AFNTYP *afnnum); diff --git a/lib/unieml.c b/lib/unieml.c index 930b2f0..518d921 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -467,22 +467,30 @@ while (proceed==true) { break; case 2 : { //scanning relayable contents int num; + char format[40]; + char ip[80]; char line[300]; num=0; + snprintf(format,sizeof(format),"%%%ld[^/]/%%d",sizeof(ip)); while (fgets(line,sizeof(line)-1,relays)!=(char *)0) { AFNTYP *afn; + int mask; num++; (void) rou_clean_conf_line(line); if (strlen(line)==0) continue; - if ((afn=afn_getoneipnum(line))==(AFNTYP *)0) { + (void) memset(ip,'\000',sizeof(ip)); + if (sscanf(line,format,ip,&mask)<1) + continue; + if ((afn=afn_getoneipnum(ip))==(AFNTYP *)0) { (void) rou_alert(0,"%s line='%03d' <%s> not a valid IP " "(error=<%s>, config?)", OPEP,num,line,strerror(errno)); continue; } + (void) afn_maskip(afn,mask); list=(AFNTYP **)rou_addlist((void **)list,(void *)afn); } } -- 2.47.3