assembly cgi program printing garbage
I have this old assembly program (nasm64) that does a good job of comparing strings in a particular way outside of CGI and I am trying to make it work as a CGI. It works correctly from the CLI but prints the typical square black boxes and question marks as a CGI (through a HTML/browser-document and Apache2), this string of garbage is always proportional to the length of the strings tested, so it is trying to print the string. In my test, ASCII strings are used but the program is intended to be used for true (non-ascii) utf-8 strings.
The same code in BASIC works perfectly (ascii tested again although the result should be the same with UTF-8 on a byte-by-byte comparison basis) but can't get the length given by CGI variable of the returned strings (how many bytes to read) and is too slow at string comparisons. I have insufficient experience in C, Perl, PHP or Python etc and only a basic knowledge of Apache2 and this strings comparison is a real bottleneck in need of assembly code that I find is my fastest way of solving that sort of problems. My questions are: What should I be looking for to solve the problem? Is Apache2 mis-configured/not-configured? I thought it was configured for UTF-8 by default and should automatically print through system call 1 (write) anything printable. Or could it be a GDM3 problem? Or a combination of both? Or do I miss something? I assume the same code in C would give the same result so a solution for C would probably solve the problem in Assembly code. Thank you for your help. Unmodified Debian 7 and Apache2 from DVD installation. New Gigabyte mobo AB350 with Feb 2017 BIOS. |
You forgot to attach the relevant code, also the problematic output.
|
Are you printing the correct HTTP headers including Content-Type, Content-Length, etc.
If you're using UTF-8, you should send Content-Type: text/html; charset=utf-8 or Content-Type: text/plain; charset=utf-8 |
Apache is generally not configured for UTF-8 by default. Supplying the charset as Laserbeak mentioned would change it for that page.
You do understand that your CGI script needs to supply HTML output in order to be viewed in a browser. At a very minimum, it needs to send Code:
Content-type: text/html Code:
<html> And to repeat NevemTeve's question...may we see the code and the output, please? |
Thank you for the answers. My apologies, I was wrongly convinced it was so simple I did not think code was necessary, I also have to do this from the local library.
Code:
bits 64 result through browser in asm Code:
��H���W(�/�IQ� Code:
Content-type: text/html Code:
#include "stdio.h" Code:
��H���W(�/�IQP� Code:
Content-Type: text/html Code:
Content-Type: text/html; charset=utf-8 |
How about sending 'HTTP/1.0 200 OK' first?
|
Quote:
|
To me, it looks like Apache is simply outputting the binary instead of executing it.
https://httpd.apache.org/docs/2.4/howto/cgi.html |
Quote:
rblampain, please show us how you are calling your program from the web page. Edit: I just remembered why that happens. (tho I just saw that this is in the link Guttorm posted) The setting Code:
AddHandler cgi-script .cgi .pl |
That is probably the problem. But I wouldn't add .asm to CGI programs, just assemble it to a binary ending in .cgi.
|
Quote:
Sorry, I get caught up in the "root cause" and forget the simple solutions -- making the solution fit the conditions instead of 'tother way 'round...I also forget that some people might not have access to the httpd.conf |
Also, make sure it's in the right "cgi-bin" directory/folder.
|
Quote:
|
So this is only DOS/Windows compatible? I tried to assemble it and it wouldn't run. When I ran "file" on it, it said "COM executable for DOS".
|
Quote:
Code:
Server error! |
All times are GMT -5. The time now is 09:56 PM. |