Advertisement

12.28.2007 at 04:16PM PST, ID: 23048359
[x]
Attachment Details

escape commands in bash script parameter

Asked by thor918 in Bourne-Again Shell (bash), Linux

Tags: bash, escape, parameter

Hi there!
is it possible to remove all sort of code injection in a parameter?

I have this ultra simple code, that uses the bash parameter in another command.
I don't want that the user has the possibility to write for example
./mybashscript '-al;rm -r /dir/;'Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
#
#!/bin/bash
#
if [ -z "$1" ]; then
echo 'ERROR'
exit 1
else
 
/bin/ls $1 #do command
error=$? # Preserve the exit code
 
if [ $error != 0 ]; then
echo 'ERROR'
else
echo 'OK'
fi
fi
[+][-]12.28.2007 at 06:28PM PST, ID: 20546543

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Bourne-Again Shell (bash), Linux
Tags: bash, escape, parameter
Sign Up Now!
Solution Provided By: Tintin
Participating Experts: 1
Solution Grade: A
 
 
[+][-]12.28.2007 at 06:43PM PST, ID: 20546578

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628