Reputation: 97
I'm trying to execute a simple c cgi-script on a hosted webserver. I compiled this code:
#include <stdio.h>
int main(){
printf("Content-type: text/plain\n\n");
printf("<html>\n");
printf("<head><title>Testing CGI-Scripts</title></head>\n");
printf("<body>\n");
printf("<h1>Hello World</h1>\n");
printf("</body>\n");
printf("</html>\n");
return 0;
}
with gcc -o index.cgi index.c
, uploaded the binary to the cgi-bin directory and changed the permission to 755. Yet when executing the script (url/cgi-bin/index.cgi) it causes a core-dump and I'm getting "500 Internal Server Error". Analyzing the core-dump with gdb got me "Cannot access memory at address 0x3000000000008" and the same line with "0x3000000000000".
I tried:
(Analysis with gdb from the static binary:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000401e82 in __libc_start_main ()
)
My System: Arch Linux, kernel 4.20.12 x86_64
Server: CloudLinux 7, kernel 3.10.0-962.3.2.lve1.5.24.8.el7 x86_64
I do not have shell access, unfortunately.
Edit: Solution:
Building a static binary on a virtual machine with CentOS (on which the Servers distro is based on) installed worked!
Upvotes: 2
Views: 191
Reputation: 785
The libraries and linker behavior may vary widely. The two distributions in question aren't even running on the same major kernel version. It sounds like you're compiling against a significantly newer version of glibc than the one that exists on your server.
I recommend you set up cross-compilation or run CloudLinux 7 in a virtual machine and compile in the VM.
Upvotes: 1