From: Jean-Marc Pigeon (Delson) Date: Fri, 9 Aug 2024 21:12:29 +0000 (-0400) Subject: Need to improve error status for tls_read X-Git-Tag: tag-0.4~3 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=dce89277e994555670e68fa114bb4af7a9dd61ab;p=jmp%2Fmailleur Need to improve error status for tls_read --- diff --git a/lib/devsoc.c b/lib/devsoc.c index 90e851c..5c230d7 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -53,38 +53,35 @@ static _Bool modopen; //module open/close status */ /********************************************************/ /* */ -/* Procedure to purge incoming plain text channel */ -/* before going to TLS mode. */ +/* Procedure to purge incoming TLS channel */ +/* After crypted link is established but before */ +/* to use it. */ /* */ /* See VE-2011-0411, "plaintext command injection" */ /* */ /********************************************************/ -static void socpurge(SOCTYP *soc) +static void socpurge(SOCTYP *soc,const char *peerip) { -_Bool needpurge; +#define OPEP "devsoc.c:socpurge" + +int max; int count; -needpurge=true; +max=1000; //purgin for one seconde max; count=0; -while (needpurge==true) { - TIMESPEC attend; - - (void) printf("JMPDBG purge\n"); - needpurge=false; +for (;countcarin=0; soc->carpile[0]='\000'; - attend.tv_sec=0; - attend.tv_nsec=1000000; //waiting one milli sec - if (soc_waitforchar(soc,&attend)>0) { - (void) printf("JMPDBG need purge count='%d'\n",count); - needpurge=true; - (void) soc_receive(soc); - count++; - if (count>10) - (void) exit(-1); - } + (void) usleep(1000); //1 millisec + (void) soc_receive(soc); + if (soc->carin==0) //got no character + break; + (void) rou_alert(0,"JMPDBG reading soc count='%d' carin='%d'",count,soc->carin); } +if (count>=max) //one second max! + (void) rou_alert(0,"%s purge is too long with peer [%s]",OPEP,peerip); +#undef OPEP } /* @@ -684,7 +681,7 @@ soc=(SOCTYP *)socptr; if (soc!=(SOCTYP *)0) { struct pollfd polling[1]; - polling[0].events=POLLIN; + polling[0].events=POLLIN|POLLPRI; polling[0].revents=(short)0; switch (soc->modtls) { case true : @@ -1075,7 +1072,7 @@ return status; /* crypted channel, return true is successful. */ /* */ /********************************************************/ -_Bool soc_starttls(SOCPTR *socptr) +_Bool soc_starttls(SOCPTR *socptr,const char *peerip) { _Bool ok; @@ -1087,13 +1084,14 @@ if ((soc!=(SOCTYP *)0)&&(soc->modtls==false)) { int tosend; char buffer[100]; + (void) socpurge(soc,peerip); tosend=snprintf(buffer,sizeof(buffer),"%d 2.0.0 Ready to start TLS%s", SIGNON,CRLF); (void) soc_writebuffer(soc,buffer,tosend); if ((soc->tls=tls_opentls(soc->handle,true))!=(TLSTYP *)0) { soc->proto=pro_smtps; soc->modtls=true; - (void) socpurge(soc); + (void) socpurge(soc,peerip); ok=true; } } diff --git a/lib/devsoc.h b/lib/devsoc.h index 3f804b2..0dd1c53 100644 --- a/lib/devsoc.h +++ b/lib/devsoc.h @@ -66,7 +66,7 @@ extern char *soc_getaddrinfo(SOCPTR *socptr,_Bool local,_Bool ip); extern SOCPTR *soc_release(SOCPTR *socptr); //procedure to initiate crypted mode on plain channel -extern _Bool soc_starttls(SOCPTR *socptr); +extern _Bool soc_starttls(SOCPTR *socptr,const char *peerip); //homework to be done before starting/stopping module. extern int soc_modedevsoc(_Bool mode); diff --git a/lib/lvleml.c b/lib/lvleml.c index 6e19ae0..14c86ef 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -142,7 +142,7 @@ while (proceed==true) { proceed=false; break; case c_starttls : //EHLO start encryptel link - switch (soc_starttls(contact->socptr)) { + switch (soc_starttls(contact->socptr,contact->peerip)) { case true : //link now in TLS crypted mode (void) tcp_signon(contact); break; diff --git a/lib/subrou.c b/lib/subrou.c index 99945cc..ee8cbf8 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -20,7 +20,7 @@ //version definition #define VERSION "0.3" -#define RELEASE "38" +#define RELEASE "39" //Public variables PUBLIC int debug=0; //debug level diff --git a/lib/unitls.c b/lib/unitls.c index 4bc6352..6dc0e6f 100644 --- a/lib/unitls.c +++ b/lib/unitls.c @@ -504,7 +504,7 @@ if (tls!=(TLSTYP *)0) { case SSL_ERROR_WANT_READ : //"wanted" error case SSL_ERROR_WANT_WRITE : (void) printf("JMPDBG SSL_get_error='%d'\n",status); - (void) usleep(1000000); + (void) usleep(1000); count++; proceed=true; break; @@ -559,7 +559,7 @@ int got; got=-1; if (tls!=(TLSTYP *)0) { - if ((got=SSL_read(tls->ssl,buffer,maxread))<=0) { + if ((got=SSL_read(tls->ssl,buffer,maxread))<0) { (void) showtlserror(tls,got,"Trouble to read data"); got=-1; }