Jump to content

C program seg faults when called in php script


naomik

Recommended Posts

I'm trying to call a program (hbplus) from the command line.

When I run the program directly from the command line, it executes successfully.  When I run the program using the script below, I get a segmentation fault.  The console output says GLIBC_2.7 is not found, but I only get this error when I call the program from php.

 

-bash-4.0$ cat hboutput

./hbplus: /lib/libc.so.6: version `GLIBC_2.7' not found (required by ./hbplus)

 

When I run my program from the command line as shown, it executes succesfully.

-bash-4.0$ ./hbplus 1PEF.pdb

 

 

<?php

echo '<pre>';

$last_line = system('./hbplus 1PEF.pdb &>hboutput', $retval);

// Printing additional info

echo '

</pre>

<hr />Last line of the output: ' . $last_line . '

<hr />Return value: ' . $retval;

?>

How would I list the environmental variables for the apache user?

 

Also, I ran the ldd command on my C executable and got this information:

-bash-4.0$ ldd hbplus

linux-gate.so.1 =>  (0x00f6d000)

libm.so.6 => /lib/libm.so.6 (0x0055b000)

libc.so.6 => /lib/libc.so.6 (0x003e8000)

/lib/ld-linux.so.2 (0x003c4000)

 

That was a good guess Jon.

 

The C code that was causing the seg fault was the following:

 

  char rcfn[256];

  strcpy(rcfn,getenv("HOME"));

 

Since apache does not have a HOME environmental variable defined, getenv returns NULL.  Then strcpy seg faults when trying to copy NULL into the buffer.

 

I just modified the C code so that it checks if getenv returns NULL, and now everything is working fine.

 

I still don't understand where the glibc error ("/lib/libc.so.6: version `GLIBC_2.7' not found") came from.

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.