]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Need to improve error status for tls_read
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 9 Aug 2024 21:12:29 +0000 (17:12 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 9 Aug 2024 21:12:29 +0000 (17:12 -0400)
lib/devsoc.c
lib/devsoc.h
lib/lvleml.c
lib/subrou.c
lib/unitls.c

index 90e851c2c19b831c548bfc33dc9504f297568d67..5c230d7832df5c4a09f01617b4b56520ee7fe84a 100644 (file)
@@ -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 (;count<max;count++) {
   soc->carin=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
 }
 /*
 \f
@@ -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;
     }
   }
index 3f804b21208fd9a10c61e0f416e4124254cb55f2..0dd1c53af127df5a0183392389a7f4806befa085 100644 (file)
@@ -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);
index 6e19ae0f2b08eba7b84561b93793648067af8d2d..14c86ef25bc7da9edb1b19b24e50993fb1a6c7c9 100644 (file)
@@ -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;
index 99945ccf1ca7db2adeebc96478f9ccaf948a3acb..ee8cbf8f2a775b07888fe2f6537206a758a9a564 100644 (file)
@@ -20,7 +20,7 @@
 
 //version definition 
 #define VERSION "0.3"
-#define RELEASE "38"
+#define RELEASE "39"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level
index 4bc63527e0783161c58d2941cedfe8f3298e7a33..6dc0e6fdce92146529b03c8de82c2e64e68cb46c 100644 (file)
@@ -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;
     }