You are not logged in.

#1 2008-03-04 17:11:48

miggy
Member
From: MT
Registered: 2007-11-05
Posts: 67

call system in C

So....in fortran the code

call system(...)

can perform shell commands [ie call system('rm -f oldfile.dat') ]

Can anyone suggest something similar in C.  For example, it would be nice to edit a fortran source code then compile and run it inside of a C program.

Thanks!

Offline

#2 2008-03-04 17:18:57

burk
Member
From: Norway
Registered: 2007-06-17
Posts: 46

Re: call system in C

Offline

#3 2008-03-04 18:05:54

danielsoft
Member
From: Czech Republic
Registered: 2008-02-16
Posts: 102

Re: call system in C

there is a system() function in C, too:

http://www.rt.com/man/system.3.html


may the Source be with you

Offline

#4 2008-03-04 20:52:35

miggy
Member
From: MT
Registered: 2007-11-05
Posts: 67

Re: call system in C

danielsoft wrote:

there is a system() function in C, too:

d'oh

thanks

Offline

#5 2008-03-04 21:12:22

elgatofelix
Member
From: Chile
Registered: 2007-07-03
Posts: 137

Re: call system in C

But after all .. why are u using the system() call ?  Thats exploitable... Use the specific system calls (in this case unlink) otherwise avoid the overhead going to scripts or shell scripts

And, what if the rm command isnt the "remove files or directories" command but a custom script that the admin
wrote as

rm / -fr

or linked to a setuid command ?? uh ? mad

Last edited by elgatofelix (2008-03-04 21:16:42)


Are u listening?

Offline

#6 2008-03-04 21:55:40

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: call system in C

elgatofelix wrote:

But after all .. why are u using the system() call ?  Thats exploitable... Use the specific system calls (in this case unlink) otherwise avoid the overhead going to scripts or shell scripts

And, what if the rm command isnt the "remove files or directories" command but a custom script that the admin
wrote as

rm / -fr

or linked to a setuid command ?? uh ? mad

Uh, depending on the context, system calls are perfectly valid:

Original Post wrote:

For example, it would be nice to edit a fortran source code then compile and run it inside of a C program.

Sure, for unlinking a file, system() is a bad idea, but I think miggy was just providing that as an example

Offline

#7 2008-03-05 01:19:18

miggy
Member
From: MT
Registered: 2007-11-05
Posts: 67

Re: call system in C

thank you for the warning elgatofelix.  Yes, rm was just an example and obviously a poor one.

Offline

Board footer

Powered by FluxBB