[packages/procmail] Add upstream memory-safety fixes, fix VAR=| capture

arekm arekm at pld-linux.org
Thu Oct 29 08:59:08 CET 2026


commit 2a7a155d1d7bca6a420de23b52341af4239df73d
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Oct 29 00:35:35 2026 +0100

    Add upstream memory-safety fixes, fix VAR=| capture

 procmail-capture-input.patch      |  76 +++++++++++++++++++
 procmail-formail-fuzz.patch       | 155 ++++++++++++++++++++++++++++++++++++++
 procmail-formail-overflow.patch   |  38 ++++++++++
 procmail-memory-safety.patch      | 146 +++++++++++++++++++++++++++++++++++
 procmail-overflow-hardening.patch | 116 ++++++++++++++++++++++++++++
 procmail-timeout-delaysig.patch   |  47 ++++++++++++
 procmail.spec                     |  19 ++++-
 7 files changed, 594 insertions(+), 3 deletions(-)
---
diff --git a/procmail.spec b/procmail.spec
index 09616cf..487ac2b 100644
--- a/procmail.spec
+++ b/procmail.spec
@@ -25,11 +25,15 @@ Patch1:		%{name}-misc.patch
 Patch2:		%{name}-FHS.patch
 Patch3:		ignore-dot.patch
 Patch4:		%{name}-c.patch
+Patch5:		%{name}-formail-overflow.patch
+Patch6:		%{name}-overflow-hardening.patch
+Patch7:		%{name}-memory-safety.patch
+Patch8:		%{name}-formail-fuzz.patch
+Patch9:		%{name}-timeout-delaysig.patch
+Patch10:	%{name}-capture-input.patch
 URL:		https://github.com/BuGlessRB/procmail
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
-%define	_debugsource_packages	0
-
 %description
 Red Hat Linux uses procmail for all local mail delivery. In addition
 to regluar mail delivery duties, procmail can be used to do many
@@ -96,10 +100,18 @@ listesi yazılımının temelini oluşturur.
 %patch -P2 -p1
 %patch -P3 -p1
 %patch -P4 -p1
+%patch -P5 -p1
+%patch -P6 -p1
+%patch -P7 -p1
+%patch -P8 -p1
+%patch -P9 -p1
+%patch -P10 -p1
 
 %build
+# K&R sources: C23 turns the () declarations into (void) prototypes
 echo "" | %{__make} \
-	CFLAGS0="%{rpmcflags} %{rpmcppflags} -w" \
+	CFLAGS0="%{rpmcflags} %{rpmcppflags} -std=gnu89" \
+	LDFLAGS0="%{rpmldflags}" \
 	SEARCHLIBS="-lm"
 
 %install
@@ -117,6 +129,7 @@ install %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/procmailrc
 :> $RPM_BUILD_ROOT/etc/skel/Mail/mbox
 
 bzip2 -dc %{SOURCE3} | tar xf - -C $RPM_BUILD_ROOT%{_mandir}
+%{__rm} $RPM_BUILD_ROOT%{_mandir}/README.procmail-non-english-man-pages
 
 %clean
 rm -rf $RPM_BUILD_ROOT
diff --git a/procmail-capture-input.patch b/procmail-capture-input.patch
new file mode 100644
index 0000000..dfb10c5
--- /dev/null
+++ b/procmail-capture-input.patch
@@ -0,0 +1,76 @@
+VAR=| cmd fed the old value of $VAR to cmd instead of the mail, so the
+capture came back empty (https://github.com/BuGlessRB/procmail/issues/5).
+Send the mail as 3.22 did; the old value stays the fallback on failure.
+
+diff --git a/src/pipes.c b/src/pipes.c
+index 93ad580..28d3c44 100644
+--- a/src/pipes.c
++++ b/src/pipes.c
+@@ -149,15 +149,16 @@ No_1st_comma: elog(*walkargs);					/* expand it */
+    }
+ }
+ 
+-int pipthrough(line,source,len)char*line,*source;const long len;
++int pipthrough(line,source,len,back,blen)char*line,*source,*back;
++ const long len,blen;			     /* back: restored if filter fails */
+ { int pinfd[2],poutfd[2];
+-  if(!source)				  /* if there's *no* source, then we */
+-     source="",PRDB=PWRB= -1;			   /* don't need a back pipe */
++  if(!back)				    /* if there's nothing to restore */
++     PRDB=PWRB= -1;			      /* then we don't need a back pipe */
+   else
+      rpipe(pbackfd);
+   rpipe(pinfd);						 /* main pipes setup */
+   if(!(pidchild=sfork()))			/* create a sending procmail */
+-   { backblock=source;backlen=len;
++   { backblock=back;backlen=blen;
+      childsetup();rclose(PRDI);rclose(PRDB);
+      rpipe(poutfd);rclose(STDOUT);
+      if(!(pidfilt=sfork()))				/* create the filter */
+diff --git a/src/pipes.h b/src/pipes.h
+index 0d92f0e..634406c 100644
+--- a/src/pipes.h
++++ b/src/pipes.h
+@@ -7,7 +7,8 @@ void
+  resettmout P((void)),
+  exectrap P((const char*const tp));
+ int
+- pipthrough P((char*line,char*source,const long len)),
++ pipthrough P((char*line,char*source,const long len,char*back,
++  const long blen)),
+  readvar P((char*const nameeq,char*const value,const long len));
+ long
+  pipin P((char*const line,char*source,long len,int asgnlastf));
+diff --git a/src/procmail.c b/src/procmail.c
+index 2e1f603..fb1ad38 100644
+--- a/src/procmail.c
++++ b/src/procmail.c
+@@ -816,20 +816,21 @@ nolock:		     { nlog("Couldn't determine implicit lockfile from");
+ 	      inittmout(buf);
+ 	      if(flags[FILTER])
+ 	       { if(startchar==themail.p&&tobesent!=filled)   /* if only 'h' */
+-		  { if(!pipthrough(buf,startchar,tobesent))
++		  { if(!pipthrough(buf,startchar,tobesent,startchar,tobesent))
+ 		       succeed=readmail(1,tobesent);
+ 		  }
+-		 else if(!pipthrough(buf,startchar,tobesent))
++		 else if(!pipthrough(buf,startchar,tobesent,startchar,tobesent))
+ 		  { filled=startchar-themail.p;
+ 		    succeed=readmail(0,tobesent);
+ 		  }
+ 	       }
+ 	      else if(capture)			  /* capturing stdout again? */
+-	       { *(chp=strchr(capture,'='))='\0';
+-		 startchar=getenv(capture);*chp='=';	  /* *NOT* tgetenv() */
+-		 tobesent=startchar?strlen(startchar):0;
+-		 if(!pipthrough(buf,startchar,tobesent))
+-		    succeed=readvar(capture,startchar,tobesent);
++	       { char*oldval;long oldlen;  /* the mail goes in, the old value */
++		 *(chp=strchr(capture,'='))='\0';    /* is restored on failure */
++		 oldval=getenv(capture);*chp='=';	  /* *NOT* tgetenv() */
++		 oldlen=oldval?strlen(oldval):0;
++		 if(!pipthrough(buf,startchar,tobesent,oldval,oldlen))
++		    succeed=readvar(capture,oldval,oldlen);
+ 		 free(capture);
+ 	       }
+ 	      else if(!pipin(buf,startchar,tobesent,1))	  /* regular program */
diff --git a/procmail-formail-fuzz.patch b/procmail-formail-fuzz.patch
new file mode 100644
index 0000000..5e103ee
--- /dev/null
+++ b/procmail-formail-fuzz.patch
@@ -0,0 +1,155 @@
+From e369ce52658a795602eb6bb04de124f36f1cc92e Mon Sep 17 00:00:00 2001
+From: "Stephen R. van den Berg" <srb at cuci.nl>
+Date: Wed, 12 Aug 2026 09:19:01 +0200
+Subject: [PATCH] Fix memory-safety bugs in formail and lockfile found by
+ fuzzing
+
+formisc.c:
+- skipcomment: stop at the end of the string instead of stepping past
+  the NUL, and don't let a trailing backslash or a nested comment walk
+  past the terminator; skipwords now bails out when skipcomment hits an
+  unterminated comment instead of skipping past the NUL
+- skipwords: when an unterminated quote or domain-literal ends at the
+  NUL, back up to it instead of continuing to parse uninitialized heap
+  bytes past the buffer
+
+formail.c:
+- NUL-terminate header fields (addfield in fields.c, plus the renfield,
+  -R and -z realloc sites) so the 'Invalid field-name' error path can
+  print field text without over-reading the heap allocation
+- reset chp before goto fromanyway: the postmark check dereferenced a
+  stale chp that still pointed into a header field freed by the -r
+  (autoreply) cleanup, causing a use-after-free in -r -s (split) mode
+
+lockfile.c:
+- initialize t so the stale-lock force check no longer compares against
+  an uninitialized timestamp when xcreat fails with EEXIST (same bug as
+  the locking.c fix)
+---
+ src/fields.c   |  3 ++-
+ src/formail.c  | 10 +++++++---
+ src/formisc.c  | 20 +++++++++++++++-----
+ src/lockfile.c |  2 +-
+ 4 files changed, 25 insertions(+), 10 deletions(-)
+
+diff --git a/src/fields.c b/src/fields.c
+index 0ce0833..e52b98c 100644
+--- a/src/fields.c
++++ b/src/fields.c
+@@ -51,9 +51,10 @@ struct field**addfield(pointer,text,totlen)struct field**pointer;
+  const char*const text;const size_t totlen;    /* add field to a linked list */
+ { register struct field*p,**pp;int idlen;
+   for(pp=pointer;*pp;pp= &(*pp)->fld_next);   /* skip to the end of the list */
+-  (*pp=p=malloc(FLD_HEADSIZ+totlen))->fld_next=0;idlen=breakfield(text,totlen);
++  (*pp=p=malloc(FLD_HEADSIZ+totlen+1))->fld_next=0;idlen=breakfield(text,totlen);
+   p->id_len=idlen>0?idlen:pp==&rdheader?0:-idlen;	    /* copy contents */
+   tmemmove(p->fld_text,text,p->Tot_len=totlen);
++  ((char*)p->fld_text)[totlen]='\0';   /* terminate, so it can be printed safely */
+   return pp;
+ }
+ 
+diff --git a/src/formail.c b/src/formail.c
+index d21e548..7f83da3 100644
+--- a/src/formail.c
++++ b/src/formail.c
+@@ -144,8 +144,9 @@ replaceall:
+   p->id_len+=(int)newl-(int)oldl;p->fld_text[p->Tot_len-1]='\n';
+   p->Tot_len=(i=p->Tot_len-oldl)+newl;
+   if(newl>oldl)
+-     *pointer=p=realloc(p,FLD_HEADSIZ+p->Tot_len);
++     *pointer=p=realloc(p,FLD_HEADSIZ+p->Tot_len+1);
+   chp=p->fld_text;tmemmove(chp+newl,chp+oldl,i);tmemmove(chp,newname,newl);
++  chp[p->Tot_len]='\0';		   /* keep the field NUL-terminated */
+ }
+ 
+ static void procfields(sareply)const int sareply;
+@@ -501,9 +502,10 @@ invfield:	     { nlog("Invalid field-name:");logqnl(chp?chp:"");
+ 		       goto usg;
+ 		     }
+ 		    *afldp=fldp=
+-		     realloc(fldp,FLD_HEADSIZ+(fldp->Tot_len=lnl+i));
++		     realloc(fldp,FLD_HEADSIZ+(fldp->Tot_len=lnl+i)+1);
+ 		    if(!copied)			   /* if not squeezed on yet */
+ 		       tmemmove((char*)fldp->fld_text+lnl,chp,i);  /* do now */
++		    ((char*)fldp->fld_text)[fldp->Tot_len]='\0';
+ 		  }
+ 	      case '\0':;
+ 	    }
+@@ -619,8 +621,9 @@ startover:
+ 	   if(chp[-1]==HEAD_DELIMITER)
+ 	      if((*chp!=' '&&*chp!='\t')&&fldp->Tot_len>j+1)
+ 	       { chp=j+(*afldp=fldp=
+-		  realloc(fldp,FLD_HEADSIZ+(i=fldp->Tot_len++)+1))->fld_text;
++		  realloc(fldp,FLD_HEADSIZ+(i=fldp->Tot_len++)+2))->fld_text;
+ 		 tmemmove(chp+1,chp,i-j);*chp=' ';
++		 ((char*)fldp->fld_text)[fldp->Tot_len]='\0';
+ 	       }
+ 	      else if(fldp->Tot_len<=j+2)
+ 	       { *afldp=fldp->fld_next;free(fldp);fldp= *afldp;
+@@ -813,6 +816,7 @@ splitit:       { if(!lnl)   /* did the previous mail end with an empty line? */
+ 	 }
+ 	else if(eqFrom_(buf))			 /* special case, From_ line */
+ 	 { addbuf();		       /* add it manually, readhead() didn't */
++	   chp=buf;		    /* point chp at it, fromanyway needs it */
+ 	   goto fromanyway;
+ 	 }
+ 	else if(split&&digest&&(lnl||every)&&artheadr())
+diff --git a/src/formisc.c b/src/formisc.c
+index 2437306..209cb47 100644
+--- a/src/formisc.c
++++ b/src/formisc.c
+@@ -20,11 +20,16 @@ static /*const*/char rcsid[]=
+ static const char*skipcomment(start)const char*start;
+ { for(;;)
+      switch(*++start)
+-      { case '\0':start--;
++      { case '\0':return start;		       /* stop at the end of the string */
+ 	case ')':return start;
+-	case '\\':start++;
+-	   break;	     /* Prithee, breaking the 11th commandment here: */
+-	case '(':start=skipcomment(start);	 /* Thou shalt not re-curse! */
++	case '\\':
++	   if(*++start=='\0')	       /* a trailing backslash, the string */
++	      start--;		      /* ends right here, don't skip past it */
++	   break;
++	case '(':
++	   if(!*(start=skipcomment(start)))	  /* the string ended right */
++	      return start;		     /* inside the comment, stop here */
++	   continue;		      /* skipcomment stopped at ')', skip past it */
+       }
+ }
+ 
+@@ -41,7 +46,9 @@ char*skipwords(start)char*start;		 /* skips an RFC 822 address */
+ 	      goto inc;
+ 	    }
+ 	   goto ret;
+-	case '(':start=(char*)skipcomment(start);		  /* comment */
++	case '(':
++	   if(!*(start=(char*)skipcomment(start)))	/* unterminated comment? */
++	      goto retz;				  /* stop right here */
+ 	case ' ':case '\t':case '\n':hitspc|=1;	       /* linear white space */
+ inc:	   start++;
+ 	   continue;
+@@ -87,6 +94,9 @@ normal:	   *target++= *start++;
+         while ((i = *target++ = *start++) && i != delim)
+ 	   if (i == '\\' && *start)		    /* skip quoted character */
+ 	      *target++ = *start++;
++	if(!i)				       /* the string ended, so back up */
++	 { target--;start--;		  /* to the NUL and stop there */
++	 }
+       }
+      hitspc=2;
+    }
+diff --git a/src/lockfile.c b/src/lockfile.c
+index f6cdc45..8a387ee 100644
+--- a/src/lockfile.c
++++ b/src/lockfile.c
+@@ -175,7 +175,7 @@ xusg:		       retval=EX_USAGE;
+      else if(sleepsec<0)      /* second pass, release everything we acquired */
+ 	unlink(cp);
+      else
+-      { time_t t;int permanent;gid_t gid=getgid();
++      { time_t t=time((time_t*)0);int permanent;gid_t gid=getgid();
+ 	if(setgid(gid)||getegid()!=gid)	      /* just to be on the safe side */
+ 	   goto sp;
+ stilv:	virgin=0;permanent=nfsTRY;
diff --git a/procmail-formail-overflow.patch b/procmail-formail-overflow.patch
new file mode 100644
index 0000000..74542dc
--- /dev/null
+++ b/procmail-formail-overflow.patch
@@ -0,0 +1,38 @@
+From c806085a2b23451e90f6f6a3293e643872a3e2dd Mon Sep 17 00:00:00 2001
+From: "Stephen R. van den Berg" <srb at cuci.nl>
+Date: Tue, 19 May 2026 15:50:35 +0200
+Subject: [PATCH] Clamp down potential buffer overflows.
+
+---
+ src/formail.c | 4 +++-
+ src/from.c    | 2 +-
+ 2 files changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/src/formail.c b/src/formail.c
+index 23c251f..d21e548 100644
+--- a/src/formail.c
++++ b/src/formail.c
+@@ -219,7 +219,9 @@ static char*getsender(namep,fldp,headreply)char*namep;struct field*fldp;
+   if(i>=0&&(i!=maxindex(sest)||fldp==rdheader))		  /* found anything? */
+    { char*saddr;char*tmp;			     /* determine the weight */
+      nowm=areply&&headreply?headreply==1?sest[i].wrepl:sest[i].wrrepl:i;chp+=j;
+-     tmp=malloc((j=fldp->Tot_len-j) + 1);tmemmove(tmp,chp,j);(chp=tmp)[j-1]='\0';
++     tmp = malloc((j = fldp->Tot_len - j) + 2);	    /* 2 spare for <> delims */
++     tmemmove(tmp, chp, j);
++     chp = tmp; tmp[j - 1] = '\0';
+      if(sest[i].head==From_)
+       { char*pastad;
+ 	if(strchr(saddr=chp,'\n'))		     /* multiple From_ lines */
+diff --git a/src/from.c b/src/from.c
+index df4ba58..63cc154 100644
+--- a/src/from.c
++++ b/src/from.c
+@@ -40,7 +40,7 @@ const char*skipFrom_(startchar,tobesentp)const char*startchar;long*tobesentp;
+ 			  /* tries to locate the timestamp on the From_ line */
+ static char*findtstamp(start,end)const char*start,*end;
+ { end-=25;
+-  if(*start==' '&&(++start==end||*start==' '&&++start==end))
++  if(*start == ' ' && (++start >= end || *start == ' ' && ++start >= end))
+      return (char*)start-1;
+   start=skpspace(start);start+=strcspn(start," \t\n");	/* jump over address */
+   if(skpspace(start)>=end)			       /* enough space left? */
diff --git a/procmail-memory-safety.patch b/procmail-memory-safety.patch
new file mode 100644
index 0000000..fac1397
--- /dev/null
+++ b/procmail-memory-safety.patch
@@ -0,0 +1,146 @@
+From 608e7ac9aee6eae6b41b84cfa62f9def62cad43a Mon Sep 17 00:00:00 2001
+From: "Stephen R. van den Berg" <srb at cuci.nl>
+Date: Wed, 12 Aug 2026 08:22:20 +0200
+Subject: [PATCH] Harden memory safety in rcfile parsing, logging, and lock
+ handling
+
+Fix out-of-bounds accesses found by an ASan/UBSan audit of the procmail
+binary (rcfile parser, mail logging, and lockfile paths):
+
+- goodies.c (readparse): add a missing CHECKINC() before the noesc write,
+  so a '$\' escape followed by a non-alphanumeric character in a
+  double-quoted string can no longer write one byte past the end of buf
+- mailfold.c (logabstract): bound the backward scan for the preceding
+  newline at themail.p, avoiding a heap under-read when a message without
+  a leading From_ line starts with a subject match
+- cstdio.c (getlline): only peek at the character before the line end
+  when the line is non-empty, avoiding a one-byte under-read of buf2 for
+  lines starting with a NUL byte
+- locking.c (lockit): initialize t so the stale-lock timeout check no
+  longer compares against an uninitialized timestamp when xcreat fails
+- authenticate.c (auth_mailboxname): initialize c so an empty pw_name
+  cannot write an uninitialized byte into the mailbox path
+
+Also harden the signal handlers against recursive logging:
+- pipes.c (ftimeout): set lck_DELAYSIG before logging from the timeout
+  handler
+- misc.c (elog): skip buffering while a signal handler is already inside
+  elog, preventing reentrant buffer corruption
+---
+ src/authenticate.c |  2 +-
+ src/cstdio.c       | 15 +++++++++------
+ src/goodies.c      |  2 +-
+ src/locking.c      |  3 ++-
+ src/mailfold.c     |  2 +-
+ src/misc.c         |  3 ++-
+ src/pipes.c        |  4 +++-
+ 7 files changed, 19 insertions(+), 12 deletions(-)
+
+diff --git a/src/authenticate.c b/src/authenticate.c
+index 1f6cd6f..5e2b3d5 100644
+--- a/src/authenticate.c
++++ b/src/authenticate.c
+@@ -193,7 +193,7 @@ const char*auth_mailboxname(pass)auth_identity*const pass;
+       strlen(pass->pw->pw_name)+1+STRLEN(MAILSPOOLSUFFIX))))
+ 	return "";
+      strcpy(pass->mbox,mailspooldir);
+-     ;{ char*p,*n;size_t i;int c;
++     ;{ char*p,*n;size_t i;int c=0;
+ 	for(p=pass->mbox+STRLEN(mailspooldir),n=pass->pw->pw_name,
+ 	 i=MAILSPOOLHASH;i--;*p++='/')
+ 	 { if(*n)
+diff --git a/src/cstdio.c b/src/cstdio.c
+index d444057..c8ff1d6 100644
+--- a/src/cstdio.c
++++ b/src/cstdio.c
+@@ -196,12 +196,15 @@ int getlline(target,end)char*target,*end;
+      switch(getbl(chp2=target,end))			   /* read line-wise */
+       { case -1:overflow=1;
+ 	case 1:
+-	   if(*(target=strchr(target,'\0')-1)=='\\')
+-	    { if(chp2!=target)				  /* non-empty line? */
+-		 target++;		      /* then preserve the backslash */
+-	      if(target>=end-2)			  /* space enough for getbl? */
+-		 target=end-linebuf,overflow=1;		/* toss what we have */
+-	      continue;
++	   ;{ char*eol;
++	      if((eol=strchr(target,'\0'))>chp2&&eol[-1]=='\\')
++	       { target=eol-1;
++		 if(chp2!=target)			  /* non-empty line? */
++		    target++;		      /* then preserve the backslash */
++		 if(target>=end-2)			  /* space enough for getbl? */
++		    target=end-linebuf,overflow=1;	/* toss what we have */
++		 continue;
++	       }
+ 	    }
+ 	case 0:
+ 	   if(overflow)
+diff --git a/src/goodies.c b/src/goodies.c
+index 538afab..dc52e37 100644
+--- a/src/goodies.c
++++ b/src/goodies.c
+@@ -94,7 +94,7 @@ Quoted:	   switch(i)
+ 		    goto nodelim;
+ 	    }
+ 	   if(got>NORMAL_TEXT)
+-noesc:	      *p++='\\';		/* nothing to escape, just echo both */
++noesc:	      CHECKINC();*p++='\\';	/* nothing to escape, just echo both */
+ 	   break;
+ 	case '`':
+ 	   if(got==SINGLE_QUOTED)
+diff --git a/src/locking.c b/src/locking.c
+index a5a0238..a7a2e6d 100644
+--- a/src/locking.c
++++ b/src/locking.c
+@@ -23,7 +23,8 @@ static /*const*/char rcsid[]=
+ char*globlock;
+ 
+ int lockit(name,lockp)char*name;char**const lockp;
+-{ int permanent=nfsTRY,triedforce=0,locktype=doLOCK;struct stat stbuf;time_t t;
++{ int permanent=nfsTRY,triedforce=0,locktype=doLOCK;struct stat stbuf;
++  time_t t=time((time_t*)0);
+   zombiecollect();
+   if(*lockp)
+    { if(!strcmp(name,*lockp))	/* compare the previous lockfile to this one */
+diff --git a/src/mailfold.c b/src/mailfold.c
+index 1c6c62c..82e8aa4 100644
+--- a/src/mailfold.c
++++ b/src/mailfold.c
+@@ -350,7 +350,7 @@ void logabstract(lstfolder)const char*const lstfolder;
+ 	if(!nextexit&&				/* don't reenter malloc/free */
+ 	 (chp=egrepin(NSUBJECT,chp,(long)(thebody-chp),0)))
+ 	 { size_t subjlen;
+-	   for(chp2= --chp;*--chp2!='\n';);
++	   for(chp2= --chp;chp2>themail.p&&*--chp2!='\n';);
+ 	   if((subjlen=chp-++chp2)>MAXSUBJECTSHOW)
+ 	      subjlen=MAXSUBJECTSHOW;		    /* keep it within bounds */
+ 	   ((char*)tmemmove(buf,chp2,subjlen))[subjlen]='\0';detab(buf);
+diff --git a/src/misc.c b/src/misc.c
+index 61d62c3..afdbd3e 100644
+--- a/src/misc.c
++++ b/src/misc.c
+@@ -40,7 +40,8 @@ void elog(newt)const char*const newt;
+   if(lnew&&				/* if this is not a forced flush and */
+    (lmax>=i||		      /* either we have enough room in the buffer or */
+     (MAXlogbuf>=i&&			 /* the buffer won't get too big and */
+-     !nextexit)))	    /* we're not in a signal handler, then it's safe */
++     !nextexit				    /* we're not in a signal handler */
++     && !(lcking&lck_LOGGING))))
+    { if(i>lmax)				      /* to use or expand the buffer */
+       { char*p;size_t newmax=lmax*2;	 /* exponential expansion by default */
+ 	if(i>newmax)				   /* ...unless we need more */
+diff --git a/src/pipes.c b/src/pipes.c
+index 177c144..88d11f5 100644
+--- a/src/pipes.c
++++ b/src/pipes.c
+@@ -47,7 +47,9 @@ void inittmout(progname)const char*const progname;
+ }
+ 
+ void ftimeout P((void))
+-{ alarm(0);alrmtime=0;toutflag=1;nlog("Timeout, ");	 /* careful, killing */
++{ alarm(0); alrmtime=0; toutflag=1;			 /* careful, killing */
++  lcking |= lck_DELAYSIG;
++  nlog("Timeout, ");
+   elog(pidchild>0&&!kill(pidchild,SIGTERM)?"terminating":"was waiting for");
+   logqnl(lastexec);signal(SIGALRM,(void(*)())ftimeout);
+ }
diff --git a/procmail-overflow-hardening.patch b/procmail-overflow-hardening.patch
new file mode 100644
index 0000000..5ae9567
--- /dev/null
+++ b/procmail-overflow-hardening.patch
@@ -0,0 +1,116 @@
+From ffe0194325adb00d478cdd99f3cac1298e05ca86 Mon Sep 17 00:00:00 2001
+From: "Stephen R. van den Berg" <srb at cuci.nl>
+Date: Tue, 19 May 2026 17:22:06 +0200
+Subject: [PATCH] Buffer overflow hardening.
+
+PLD: when the bogus-mailbox name does not fit, rnmbogus() returns failure
+instead of logging a rename that never happened and returning success.
+
+---
+ src/foldinfo.c  | 31 +++++++++++++++++++++----------
+ src/mailfold.c  |  5 ++++-
+ src/variables.c | 17 +++++++++++------
+ 3 files changed, 36 insertions(+), 17 deletions(-)
+
+diff --git a/src/foldinfo.c b/src/foldinfo.c
+index 48b83e2..051b257 100644
+--- a/src/foldinfo.c
++++ b/src/foldinfo.c
+@@ -55,16 +55,24 @@ int rnmbogus(name,stbuf,i,dolog)const char*const name;	      /* move a file */
+  const struct stat*const stbuf;const int i,dolog;	   /* out of the way */
+ { static const char renbogus[]="Renamed bogus \"%s\" into \"%s\"",
+    renfbogus[]="Couldn't rename bogus \"%s\" into \"%s\"",
+-   bogusprefix[]=BOGUSprefix;char*p;
+-  p=strchr(strcpy(strcpy(buf2+i,bogusprefix)+STRLEN(bogusprefix),
+-   getenv(lgname)),'\0');
+-  *p++='.';ultoan((unsigned long)stbuf->st_ino,p);	  /* i-node numbered */
+-  if(dolog)
+-   { nlog("Renaming bogus mailbox \"");elog(name);elog("\" info");
+-     logqnl(buf2);
++   bogusprefix[]=BOGUSprefix;
++  char *p = getenv(lgname);
++  if (i + STRLEN(bogusprefix) + strlen(p) + 1
++    + (sizeof(stbuf->st_ino) * 8 + 7) / 3 <= linebuf)
++   { p = strchr(strcpy(strcpy(buf2 + i, bogusprefix) + STRLEN(bogusprefix),
++                       p), '\0');
++     *p++='.';ultoan((unsigned long)stbuf->st_ino,p);	  /* i-node numbered */
++     if(dolog)
++      { nlog("Renaming bogus mailbox \"");elog(name);elog("\" info");
++        logqnl(buf2);
++      }
++     if(rename(name,buf2))		   /* try and move it out of the way */
++      { syslog(LOG_ALERT,renfbogus,name,buf2);		 /* danger!  danger! */
++        return 1;
++      }
+    }
+-  if(rename(name,buf2))			   /* try and move it out of the way */
+-   { syslog(LOG_ALERT,renfbogus,name,buf2);		 /* danger!  danger! */
++  else			   /* no room for the new name, leave it in place */
++   { syslog(LOG_ALERT,renfbogus,name,"");
+      return 1;
+    }
+   syslog(LOG_CRIT,renbogus,name,buf2);
+@@ -298,7 +306,10 @@ fishy:
+    }
+   if(!S_ISDIR(stbuf.st_mode))
+    { int isgrpwrite=stbuf.st_mode&S_IWGRP;
+-     strcpy(chp=strchr(buf,'\0'),lockext);
++     chp = strchr(buf,'\0');
++     if (chp - buf + STRLEN(lockext) >= linebuf)
++        goto nl;			      /* not enough room for lockext */
++     strcpy(chp, lockext);
+      defdeflock=tstrdup(buf);
+      if(!isgrpwrite&&!lstat(defdeflock,&stbuf)&&stbuf.st_uid!=uid&&
+       stbuf.st_uid!=ROOT_uid)
+diff --git a/src/mailfold.c b/src/mailfold.c
+index 873a5d3..1c6c62c 100644
+--- a/src/mailfold.c
++++ b/src/mailfold.c
+@@ -200,8 +200,11 @@ int writefolder(boxname,linkfolder,source,len,ignwerr,dolock)
+      type=ft_PIPE;
+      goto dumpc;
+    }
+-  if(boxname!=buf)
++  if (boxname != buf)
++   { if (strlen(boxname) >= linebuf)
++       goto retf;
+      strcpy(buf,boxname);		 /* boxname can be found back in buf */
++   }
+   if(linkfolder)		    /* any additional directories specified? */
+    { size_t blen;
+      if(blen=Tmnate-linkfolder)		       /* copy the names into safety */
+diff --git a/src/variables.c b/src/variables.c
+index 50c5258..b434295 100644
+--- a/src/variables.c
++++ b/src/variables.c
+@@ -103,8 +103,11 @@ void retStdout(newmyenv,fail,unset)		/* see note on primeStdout() */
+   retbStdout(newmyenv);
+   var=newmyenv+ioffsetof(struct dynstring,ename[0]);	    /* setup to copy */
+   p=strchr(var,'=');			       /* the variable name into buf */
+-  tmemmove(buf,var,p-var);			     /* so that we can check */
+-  buf[p-var]='\0';						/* for magic */
++  if (p - var < linebuf)
++   { tmemmove(buf, var, p - var);		     /* so that we can check */
++     buf[p - var] = '\0';					/* for magic */
++   } else
++     buf[0] = '\0';				  /* too long to check magic */
+   if(fail)
+      asenvtext(p+1);	  /* we always have to update the pointers for these */
+   else
+@@ -141,10 +144,12 @@ void setval(name,value)const char*const name,*const value;  /* destroys buf2 */
+ 
+ void setdef(name,value)const char*const name,*const value;
+ { char*p;
+-  strcpy(buf,name);				 /* insert the variable name */
+-  p=strchr(buf,'\0');					   /* (find the end) */
+-  *p++='=';						       /* then the = */
+-  eputenv(value,p);			/* expand the value and call sputenv */
++  if (strlen(name) + strlen(value) < linebuf) {
++    strcpy(buf, name);				 /* insert the variable name */
++    p = strchr(buf,'\0');				   /* (find the end) */
++    *p++ = '=';						       /* then the = */
++    eputenv(value, p);			/* expand the value and call sputenv */
++  }
+ }
+ 
+ const char*tgetenv(a)const char*const a;
diff --git a/procmail-timeout-delaysig.patch b/procmail-timeout-delaysig.patch
new file mode 100644
index 0000000..fd85290
--- /dev/null
+++ b/procmail-timeout-delaysig.patch
@@ -0,0 +1,47 @@
+From 8b379c4f536320abafd524fd4ccfedaf3f387f54 Mon Sep 17 00:00:00 2001
+From: "Stephen R. van den Berg" <srb at cuci.nl>
+Date: Wed, 12 Aug 2026 09:45:49 +0200
+Subject: [PATCH] Fix lck_DELAYSIG leak in the timeout handler
+
+ftimeout sets lck_DELAYSIG to defer Terminate() while it logs, but never
+cleared it, leaving the process permanently in 'signals delayed' state
+after any timeout.  Subsequent SIGTERM/SIGINT/SIGHUP/SIGQUIT were then
+deferred to the next lock boundary (or swallowed in paths that never
+lock again), and sterminate's diagnostic was suppressed.
+
+Clear the flag once the logging is done and reap a deferred termination
+(nextexit==1) the same way offguard() does.  Fixes a regression since
+the recent signal-handler fix.
+
+PLD: keep lck_DELAYSIG set when the alarm interrupted a section that
+already had it (lockit(), onguard()), that section reaps the signal.
+---
+ src/pipes.c | 13 ++++++++++---
+ 1 file changed, 10 insertions(+), 3 deletions(-)
+
+diff --git a/src/pipes.c b/src/pipes.c
+index 88d11f5..93ad580 100644
+--- a/src/pipes.c
++++ b/src/pipes.c
+@@ -47,11 +47,18 @@ void inittmout(progname)const char*const progname;
+ }
+ 
+ void ftimeout P((void))
+-{ alarm(0); alrmtime=0; toutflag=1;			 /* careful, killing */
+-  lcking |= lck_DELAYSIG;
++{ int delayed=lcking&lck_DELAYSIG;	 /* interrupted a guarded section? */
++  alarm(0); alrmtime=0; toutflag=1;			 /* careful, killing */
++  lcking |= lck_DELAYSIG;	       /* defer Terminate while we log */
+   nlog("Timeout, ");
+   elog(pidchild>0&&!kill(pidchild,SIGTERM)?"terminating":"was waiting for");
+-  logqnl(lastexec);signal(SIGALRM,(void(*)())ftimeout);
++  logqnl(lastexec);
++  if(!delayed)			  /* else the guarded section reaps it */
++   { lcking &= ~lck_DELAYSIG;		/* restore normal signal semantics */
++     if(nextexit==1)		       /* reap a termination signal that */
++	Terminate();			     /* arrived while we were logging */
++   }
++  signal(SIGALRM,(void(*)())ftimeout);
+ }
+ 
+ void resettmout P((void))
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/procmail.git/commitdiff/2a7a155d1d7bca6a420de23b52341af4239df73d



More information about the pld-cvs-commit mailing list