]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Fix big bug with sock_purge (at starttls)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 18 Jul 2025 19:47:26 +0000 (15:47 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 18 Jul 2025 19:47:26 +0000 (15:47 -0400)
lib/devsoc.c
lib/devsoc.h
lib/lvleml.c
lib/unitls.c

index 105ba11ac5374db07a8e9e0b118be3242bf37b3b..f696ba6d3e79272b617ce55feeeeded76aabdfa8 100644 (file)
@@ -46,40 +46,6 @@ typedef struct  {
         int iteration;  //number of soc slot used on the IP
         }SOCTYP;
 
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
-/*     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,const char *peerip)
-
-{
-#define OPEP    "devsoc.c:socpurge"
-
-int max;
-int count;
-
-max=1000;       //purging for 1 seconde max;
-count=0;
-for (;count<max;count++) {
-  soc->carin=0;
-  soc->carpile[0]='\000';
-  (void) usleep(1000);  //1 millisec
-  (void) soc_receive(soc);
-  if (soc->carin==0)    //got no character
-    break;
-  }
-if (count>=max) //one second max!
-  (void) rou_alert(0,"%s purge is too long with peer [%s]",OPEP,peerip);
-#undef  OPEP
-}
 /*
 \f
 */
@@ -1502,6 +1468,46 @@ while (proceed==true) {
   phase++;
   }
 return socptr;
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to purge incoming TLS channel         */
+/*      After crypted link is established but before    */
+/*      to use it.                                      */
+/*                                                     */
+/*      See VE-2011-0411, "plaintext command injection" */
+/*                                                      */
+/********************************************************/
+PUBLIC void soc_purge(SOCPTR *socptr,const char *peerip)
+
+{
+#define OPEP    "devsoc.c:soc_purge,"
+
+int max;
+int count;
+
+max=1000;       //purging for 1 seconde max;
+count=0;
+if (socptr!=(SOCPTR *)0) {
+  SOCTYP *soc;
+
+  soc=(SOCTYP *)socptr;
+  for (;count<max;count++) {
+    soc->carin=0;
+    soc->carpile[0]='\000';
+    (void) usleep(1000);  //1 millisec
+    (void) soc_receive(soc);
+    if (soc->carin==0)    //got no character
+      break;
+    }
+  }
+if (count>=max) //one second max!
+  (void) rou_alert(0,"%s purge is too long with peer [%s]",OPEP,peerip);
+
 #undef  OPEP
 }
 /*
@@ -1524,16 +1530,10 @@ SOCTYP *soc;
 ok=false;
 soc=(SOCTYP *)socptr;
 if ((soc!=(SOCTYP *)0)&&(soc->modtls==false)) {
-  char *peerip;
-
-  peerip=(char *)0;
   switch (server)       {
-    case true   :
-      peerip=soc_getaddrinfo(socptr,false,false);
-      (void) socpurge(soc,peerip);
-      peerip=rou_freestr(peerip);
+    case true   :       //Nothing to do?
       break;
-    case false  :
+    case false  :       //Nothing to do?
       break;
     }
   soc->tls=tls_opentls(soc->handle,server);
index db4460957780befb558d4e6571723c4e4c3eec25..6f5e587feeeec87d4d98b9f54c090aebe093f40b 100644 (file)
@@ -69,6 +69,9 @@ extern char *soc_getaddrinfo(SOCPTR *socptr,_Bool local,_Bool getname);
 //procedure to release/clsoe socket
 extern SOCPTR *soc_release(SOCPTR *socptr);
 
+//procedure to purge contact chenel (used in case of starttls)
+extern void soc_purge(SOCPTR *socptr,const char *peerip);
+
 //procedure to initiate crypted mode on plain channel
 extern _Bool soc_starttls(SOCPTR *socptr,_Bool server);
 
index b146d0313894655b188f3a4fc798159c80b472dd..90b6d3a0878a059add2a146298a4c309d206233e 100644 (file)
@@ -1695,7 +1695,7 @@ while (proceed==true) {
           break;
         }
       break;
-    case 1      :       //Stating starttls
+    case 1      :       //Starting starttls
       phase=999;        //No need to go futher
       rspcode=simple_smtp_command(rmt,"STARTTLS",rmt->orgdomain);
       switch (rspcode) {
@@ -2335,6 +2335,7 @@ while (proceed==true) {
       break;
     case c_starttls     :       //EHLO start encrypted link in server mode
       (void) usleep(100000);
+      (void) soc_purge(contact->socptr,contact->peerip);
       (void) transmit(contact,true,"%d 2.0.0 Ready to start TLS",SIGNON);
       switch (soc_starttls(contact->socptr,true)) {
         case true       :  {    //link now in TLS crypted mode (server mode)
index 8077b7b547cd7d2bfeb0747a2fed5524488005f5..f61ac64d6caa73dfd5d9ebc6d2e846e242dc71d0 100644 (file)
@@ -251,7 +251,7 @@ mode=SSL_VERIFY_NONE;
 phase=0;
 proceed=true;
 while (proceed==true) {
-  (void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase);
+  //(void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase);
   switch (phase) {
     case 0      :       //loading certificate names
       for (int i=0;i<(sizeof(cenv)/sizeof(char *));i++) {