Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is there a way to safely encode / pass arguments to a shell command where the argument might be binary? I'm executing a command from within a PHP script that allows for user data. For security, however, I obviously want this data escaped. Moreover, sometimes the data may be binary in nature so simple quoting of the shell command doesn't seem like it would suffice. What's the best approach for making sure a shell command's argument is properly escaped even if the argument data is binary?

share|improve this question
    
I am very curious as what shell command you intend to call with binary data as an argument, instead of piped into stdin. –  DerfK Jan 4 at 0:48

1 Answer 1

up vote 1 down vote accepted

You can encode it as base64 in PHP using base64_encode(), pass it to the shell, then decode it in the shell using base64 --decode.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.