[neomutt-devel] [BUG] Segfault while editing mail header

Viresh Kumar viresh.kumar at linaro.org
Tue Apr 30 13:02:09 CEST 2019


Hello,

I updated neomutt to the master branch today (c6e4b7039cdd) and since
then I started encountering segfaults with my special usecase. I bisected
it to commit 04aa08d955e3 ("Fix segfault introduced by 5e8cb63").
I can't simply revert it over master branch due to conflicts and so
this mail to seek help in fixing my issue.

My usecase:

I add labels to the subject line of emails for better management, like
pending, applied, etc. I do it with the help of my editlabel script
(attached) and following in my .muttrc:

-------------------------8<-------------------------

# Labels to mark messages pen,apply
macro index ",1" "<enter-command>set editor=\"~/scripts/editlabel append "pen"\"\n\
<edit><sync-mailbox><next-undeleted>\
<enter-command>set editor=vim\n"

bind index . noop
macro index ".1" "<enter-command>set editor=\"~/scripts/editlabel remove "pen"\"\n\
<edit><sync-mailbox><next-undeleted>\
<enter-command>set editor=vim\n"

-------------------------8<-------------------------

So when I press ,1 for a subject line it adds [pen] before it, which I can later remove with .1

I tried to debug it a bit and everything works well with editlabel
script until the last action is performed (mv $NFNAME $FNAME) which
tries to copy the edited file back to make an update and that's when I
get segfault.

There is something in the above commit, 04aa08d955e3, which makes it
break for my usecase. Can someone help  please ?

-- 
viresh
-------------- next part --------------
#!/bin/bash

# $1 is the action (append, show, remove)
# $3 is the filename

# Configuration
LFILE="$HOME/.labels"

#echo $0
#echo $1 
#echo $3
#echo $3
#exit

ACTION="$1"
LNAME="$2"
FNAME="$3"
NFNAME="/tmp/editlabels-`basename "$3"`.$$"

function asklabel() {
	read -e -p "Insert label: " $1
	CVAL=${!1}
	while ( ! grep -q "^$CVAL$" "$LFILE" ) || ( [ "$CVAL" == "" ] ) ; do
		echo "Invalid label \"$CVAL\""
		read -e -p "Insert label: " $1
		CVAL=${!1}
	done
}


if [ "$ACTION" == "menu" ]; then
	function getact() {
		read -p "Append/Remove/Show/Clean/List: " ACT
		if [ "$ACT" == "a" ]; then
			ACTION=append
		elif [ "$ACT" == "r" ]; then
			ACTION=remove
		elif [ "$ACT" == "s" ]; then
			ACTION=show
		elif [ "$ACT" == "c" ]; then
			ACTION=clean
		elif [ "$ACT" == "l" ]; then
			ACTION=list
		else
			echo "Invalid action"
			getact
		fi
	}
	getact
fi


if [ "$ACTION" == "append" ]; then
	ACT=`formail -c -X X-Label < "$FNAME"`
#	asklabel LNAME
	if [ "$ACT" == "" ]; then
		NEW="X-Label: $LNAME"
	else
		NEW="$ACT, $LNAME"
	fi

	formail -I "$NEW" < "$FNAME" > "$NFNAME"

elif [ "$ACTION" == "remove" ]; then
	ACT=`formail -c -X X-Label < "$FNAME"`
#	asklabel LNAME
	NEW=`echo $ACT | sed "s/, $LNAME//g" | sed "s/$LNAME, //g" | sed "s/: $LNAME/:/g"`
	formail -I "$NEW" < "$FNAME" > "$NFNAME"

elif [ "$ACTION" == "show" ]; then
	formail -c -X "X-Label:" < "$FNAME"
	read -p "Press any key to continue"

elif [ "$ACTION" == "clean" ]; then
	formail -I "X-Label:" < "$FNAME" > "$NFNAME"

elif [ "$ACTION" == "list" ]; then
	echo "Available labels (from ~/.labels):"
	cat $LFILE
	read -p "Press any key to continue"
fi


# if we created a new file, step over the old one
if [ -f "$NFNAME" ]; then
	mv $NFNAME $FNAME
fi



More information about the neomutt-devel mailing list