fir3net
PPS-Firenetbanner-780.5x190-30-03-17

Bash / CGI - Premature end of script headers

Issue

When trying to add a image to your CGI script you recieve the following error and the image isnt displayed.

[root@localhost cgi-bin]# cat /var/log/httpd/error_log
[Fri Jul 10 20:51:39 2009] [error] [client 10.2.2.5] Premature end of script headers: picture2.jpg, referer: http://10.2.2.1/cgi-bin/picture.cgi
[Fri Jul 10 20:57:57 2009] [error] [client 10.2.2.5] (8)Exec format error: exec of '/var/www/cgi-bin/picture2.jpg' failed, referer: http://10.2.2.1/cgi-bin/picture.sh

Solution

Add to your httpd.conf or apache.conf file an alias such as,

Alias /images/legacy/ /usr/share/images/legacy/

Once added restart you httpd/apache daemon. And add your images to the directory.

#!/bin/sh
unset PATH
echo "Content-type: text/html"
echo ""
echo "<html>"
echo    "<body>"
echo            "<img src="/images/legacy/picture.jpg">"
echo    "</body>"
echo "</html>"

 Your page should now display the picture.

About the Author

RDonato

R Donato

Rick Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001