Re: Incompatible pointer type
Re: Incompatible pointer type
- Subject: Re: Incompatible pointer type
- From: Gary McGill <email@hidden>
- Date: Fri, 15 Jan 2010 17:50:17 -0500
- Thread-topic: Incompatible pointer type
Title: Re: Incompatible pointer type
You make some good points. Although it is a private database I am working with, if I ever decide to sell my CRM program I would like it to be as bullet-proof as possible. The phone number could have a * in it or some other character to get an outside line.
I will look at changing it to NSTask.
Thanks for your comments.
Gary
On 1/15/10 11:46 AM, "Jens Alfke" <email@hidden> wrote:
On Jan 15, 2010, at 7:23 AM, Gary McGill wrote:
I am trying to pass a variable to system(). The final code would look like this:
system(“lp –d Internal_Modem –o phone=555-5555 ~/Desktop/fileToFax.pdf”)
If I simply put this line in my code, it works fine. The problem is I have to get the phone number from the database. When I build the string using AppendString [...]
Earlier replies have addressed your immediate problem, but I want to recommend that you not call system().
(1) Assembling command-line strings is messy, because you have to deal with issues of shell quoting. In your case, can a phone number contain a "*" or "#"? Either one will confuse the shell and make the command fail. In general this can be a nightmare to deal with. In the worst case, if you don't trust the data source, this can allow hackers to exploit your app to run arbitrary code (e.g. passing in a phone number like "0; rm -rf ~;") — this has been the cause of many, many, many attacks on websites and other systems.
(2) You don't know which shell is going to run the command — probably bash, but some people (like me) use tcsh, and there's also zsh. All have subtle differences in the way they parse commands.
(3) Launching a shell has overhead. Probably not an issue in your case, but if you call this a lot it can be noticeable.
(4) Why use a Unix system call when there are friendly Cocoa classes that do the same thing?
What you should be using instead is NSTask. It will let you pass the arguments as individual NSStrings (so no C-string conversion or concatenation to do), they don't get run through a shell or otherwise parsed (so no worries about quoting), and it directly launches the binary (so better performance.)
—Jens
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden