You are not logged in.

#1 2021-11-10 05:59:50

N_BaH
Member
Registered: 2015-12-30
Posts: 72

[solved] groff segmentation fault in CGI

hi,

I'm writing a simple man2html CGI script :

#!/bin/bash

printf 'Content-type: text/html\n\n'
echo '<!doctype html>'
exec 2>&1
set -x
zcat /usr/share/man/man1/man.1.gz | groff -man -Thtml -
set +x

this script works well on Debian.
here's what I get on Archlinux:

+ zcat /usr/share/man/man1/man.1.gz
+ groff -man -Thtml - /srv/http/cgi-bin/test: line 7: 94180 Done zcat /usr/share/man/man1/man.1.gz 94181 Segmentation fault (core dumped) | groff -man -Thtml -
+ set +x

I have other CGI scripts that work as intended.

Last edited by N_BaH (2021-11-18 18:00:13)

Offline

#2 2021-11-10 07:07:13

seth
Member
Registered: 2012-09-03
Posts: 25,134

Re: [solved] groff segmentation fault in CGI

So…? Maybe look at the coredump?
https://wiki.archlinux.org/title/Core_d … _core_dump

Online

#3 2021-11-10 07:23:47

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

here's what I get from gdb backtrace

Reading symbols from /usr/bin/groff...
(No debugging symbols found in /usr/bin/groff)
[New LWP 143950]
Core was generated by `groff -man -Thtml'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f14035b34c7 in __strchr_sse2 () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007f14035b34c7 in __strchr_sse2 () from /usr/lib/libc.so.6
#1  0x00005642eaf6aa7a in ?? ()
#2  0x00005642eaf6ad0e in ?? ()
#3  0x00005642eaf6af35 in ?? ()
#4  0x00005642eaf621b1 in ?? ()
#5  0x00007f140353cb25 in __libc_start_main () from /usr/lib/libc.so.6
#6  0x00005642eaf6293e in ?? ()
(gdb) 

but it doesn't tell me much.
do you need more?

btw, there's one big difference between Debian and Arch installations : the former uses apache2, the latter uses lighttpd.

Offline

#4 2021-11-10 07:55:39

seth
Member
Registered: 2012-09-03
Posts: 25,134

Re: [solved] groff segmentation fault in CGI

It crashes in the sse2 implementation of strchr
Can you reproduce this interactively

zcat /usr/share/man/man1/man.1.gz | groff -man -Thtml -
zcat /usr/share/man/man1/man.1.gz > /tmp/man.1; groff -man -Thtml /tmp/man.1

And on a hunch

localectl
locale
locale -a

Online

#5 2021-11-10 15:09:29

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

interactively, `zcat | groff' work fine, as using an intermediate file.

here's the result of additional commands :

$ localectl
   System Locale: LANG=fr_FR.UTF-8
       VC Keymap: fr-latin9
      X11 Layout: n/a
$ locale
LANG=fr_FR.UTF-8
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=
$ locale -a
C
fr_FR.utf8
nl_NL.utf8
POSIX
$ 

Offline

#6 2021-11-10 15:18:03

seth
Member
Registered: 2012-09-03
Posts: 25,134

Re: [solved] groff segmentation fault in CGI

Locale looks fine - does running your script interactively crash?
What if you don't redirect stderr into stdout?

Online

#7 2021-11-10 16:22:03

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

in a terminal, the script works perfectly.
I redirected stderr because nothing appeared in browser. smile
if I don't, I have no man page, and no error message in browser. sad

Offline

#8 2021-11-10 16:36:59

seth
Member
Registered: 2012-09-03
Posts: 25,134

Re: [solved] groff segmentation fault in CGI

Can you

zcat /usr/share/man/man3/strchr.3.gz | groff -man -Thtml - # shorter file …
zcat /usr/share/man/man3/strchr.3.gz | groff -man -Tascii - # … and less effort

Online

#9 2021-11-10 16:50:19

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

they both cause segmentation fault.

Last edited by N_BaH (2021-11-10 17:01:31)

Offline

#10 2021-11-10 17:12:16

seth
Member
Registered: 2012-09-03
Posts: 25,134

Re: [solved] groff segmentation fault in CGI

Do you use the cgi or the fastcgi module?
System is fully updated? No partital updates?

Online

#11 2021-11-10 18:02:08

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

cgi module is cgi (no fastcgi).
system is fully updated; non partial update.

Last edited by N_BaH (2021-11-10 22:23:13)

Offline

#12 2021-11-10 22:23:20

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

I installed apache2 using simple cgi_mod on an lxc machine, and finally made the script work in the container.
so, the problem seems to come from lighttpd...

Offline

#13 2021-11-11 07:55:24

seth
Member
Registered: 2012-09-03
Posts: 25,134

Re: [solved] groff segmentation fault in CGI

finally made the script work in the container

?
Is lighttpd also a container installation??
Because in that case it is *faaaaaar* more likely the container and the contained glibc…

Online

#14 2021-11-11 13:29:14

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

no, lighttpd is on hardware.

Offline

#15 2021-11-12 04:19:07

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

as it seems to be a lighttpd issue, should I close this thread and open a new one under "Networking, Server and Protection" section?

Offline

#16 2021-11-12 07:35:12

seth
Member
Registered: 2012-09-03
Posts: 25,134

Re: [solved] groff segmentation fault in CGI

It's not network related but programming & scripting is false as well, since it's not about your script either.

If you suffix the script .sh and assign that to /usr/bin/bash, does it still segfault?
https://wiki.archlinux.org/title/Lighttpd#CGI

Online

#17 2021-11-12 14:12:23

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

assigning .sh to /usr/bin/bash doesn't change a thing : it still "segfaults".

here's /etc/lighttpd/lighttpd.conf :

# See /usr/share/doc/lighttpd
# and http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions

server.port		= 80
server.username		= "http"
server.groupname	= "http"
server.document-root	= "/srv/http"
server.errorlog		= "/var/log/lighttpd/error.log"
dir-listing.activate	= "enable"
index-file.names	= ( "index.html", "cgi-bin/accueil" )
mimetype.assign		= (
				".html" => "text/html",
				".txt" => "text/plain",
				".css" => "text/css",
				".js" => "application/x-javascript",
				".jpg" => "image/jpeg",
				".jpeg" => "image/jpeg",
				".gif" => "image/gif",
				".png" => "image/png",
				"" => "application/octet-stream"
			)
server.modules += ( "mod_userdir" )
userdir.path = "public_html"

server.modules += ( "mod_cgi" )
cgi.assign = (
	".sh" => "/usr/bin/bash" #this doesn't change wrong behaviour
)
#$HTTP["url"] =~ "^(/~[^/]+)?/cgi-bin/" { #this is default config found on internet; it works with other CGI shell scripts.
#	cgi.assign = ("" => "")
#}

# PDF view files instead of downloading
#https://azgtech.wordpress.com/2011/01/26/force-download-pdf-using-lighttpd/
#https://stackoverflow.com/questions/6293893/how-do-i-force-files-to-open-in-the-browser-instead-of-downloading-pdf
server.modules += ( "mod_setenv" )
$HTTP["url"] =~ "(.*)\.pdf" {
	mimetype.assign = (".pdf" =>"application/pdf")
	setenv.add-response-header = ( "Content-Disposition" => "inline" )
}
# Redirection
$HTTP["host"] == "machine_name" {
	$HTTP["url"] =~ "^/$" {
		url.redirect = ( "" => "/cgi-bin/home" )
		url.rediect-code = 302
	}
}

Last edited by N_BaH (2021-11-12 14:13:20)

Offline

#18 2021-11-18 18:02:46

N_BaH
Member
Registered: 2015-12-30
Posts: 72

Re: [solved] groff segmentation fault in CGI

silly me !
groff uses so many "sub programs", I remember that I tested PATH variable, though.
I probably didn't refresh browser's cache.

so, I set PATH to /usr/local/sbin:/usr/local/bin:/usr/bin, and I don't have segfault any more.

thnak you for your time, and sorry for such a simple error.

Offline

Board footer

Powered by FluxBB