Skip to main content

CGI & HTTP 500

I'am currently writing a small app in C that should display a timetable, on a Solaris 10/Apache Sun server.
The app should open a HTML skeleton, syntaxicaly replace a couple of placeholders and display the content.
If the skeleton could not be found, an HTML error message is sent back to the user.
I compile, and test it: runs #1.
I move my executable in the cgi-bin folder and invoke it with my browser and .. bang!: HTTP 500.
The error_log shows:

malformed header from script. Bad header=<HTML>: /apache/web/cgi-bin/timesheet.cgi


The HTTP-500 arises mostly when Content-type:... is missing, or if there's not empty line before the text.
However, in my case, when I invoked it manually:

/apache/web/cgi-bin/timesheet.cgi

.. it worked perfectly, displaying it could find its skeleton:

Content-type: text/html

<html>
[... Error message ...]
</html>

So what was going on?
I replaced the binary by a small script displaying the error message, hit it with my brower ... and it worked!
So, I was facing a situation when my executable crashed when a smallscript displaying exactly the same message worked.
Okay, I give you the trick (it took me truss to figure out what was going on under the hood): remember my executable should display the error message if the skeleton was missing. But the skeleton was actually in place. Then, when I invoke the executable from a place elsewhere than the cgi-bin folder, it couldn't find the skeleton and display the error message. But invoked by Apache, in was in the right context, found its skeleton, did its placeholder-replacements and display the content ... without Content-type:... because it was missing in the skeleton!
Grrr! It took me 2 days to figure out this bug.

Comments

Popular posts from this blog

Update to Ubuntu 24.04

After years running Ubuntu 20.04, I recently (January 2025) installed Ubuntu 24.04 Noble Numbat. This cames with few improvements and a couple of disappointments, mainly the lost of my dual-screen: my graphic card, Nvidia Quadro FX3700, is not supported anymore by the latest driver. The result is: when the computer boots up, it does on output 0 (right screen). But as soon as Wayland starts, it switches to output 1 (left screen), ignoring the other output; my right screen remains black. This is a new behavior, it works fine on 20.04. Keyboard I write mainly in French and English. My keyboard is US Qwerty with US International layout. In English, what I see on keyboard is what I get on screen. In French, the diacritics are obtained with compositional keys: To get Ubuntu 20 Ubuntu 24 á é í ó ú ý Á É Í Ó Ú Ý ' e (Quote letter) ' E (Quote shift+letter) à è ...

Drive replacement for Fostex DMT8-vl

The IDE hard drive on my Fostex DMT8-vl multitrack recorder shows signs of its imminent death; when getting hot, I could not record anymore. Must be said this drive comes from an old Sun Station, and has been replaced because I/O failures were detected by Solaris. It worked at least 5 years in my recorder: not so bad. However, time is now to replace it. The DMT8-vl is not able to handle drives bigger than 8.4 GB. Well, it is able to (the current drive is 15 GB), but only 8.4 GB will be usable. My tought was to use a 8 GB CompactFlash; having no moving parts means no noise, which is quite temptating for a music recording device. I purchased a CompactFlash-IDE adapter on the internet (8$) and I had to build a male-male IDE cable adapter (4$). Unfortunately, this doesn't work. The drive is correctly discovered by the operating system, which proposes to format it ("format IDE?"). After answering "yes", the formating runs pretty fast (faster than on a real drive), ...

My journey with ATtiny4313 (part 1)

Introduction The context For a personal project, I want to program an Atmel ATtiny4313 microcontroller. I use microcontrollers for several years, but not on a regular basis (maybe 3-4 times a year), mostly for testing and generally with a deceptive result. But failure isn't the best training? This article aims to share my errors and success, as well as being a personal log. The project The project is to replace the main board of a Soundpool MO4, a MIDI OUT extension for the Atari ST; details here . Overall, the project is pretty simple: reading the parallel port and copy verbatim the data to MIDI out. This is the reason behind my choice of this particular microcontroller, since it embeds an USART and has an 8 bits parallel port (20 pins DIP package). The MO4 having 4 MIDI Outs, I will use 4 ATTiny4313, one for each out; this is actually cheaper than finding a 4-channel USART. Each microcontroller must determine if the data present on the parallel port shoul...