I have a C++ generated executable in Solaris 8. The problem I have is that this executable uses a command line parameter to run.
For example:
$ myprog 123412341234AB
This is a valid 14 digit hexdecimal value. However, if for some reason there are symbols like ^ > < >> << & etc., then the program does not behave properly per se. I am not talking core dumps per se but
for example one of the checks I do is via isxdigit. Apparently it is not good enough to catch
something like 1234123412341^ or 12341234(12341, so I am just trying to see if I can detect all these symbols in an effort to just exit properly. I mean, some of these symbols have special meaning in Unix and I guess that is why the program does not understand how to handle it.
Do you have any thoughts on how to address this? Do I just try to find all these symbols and the moment I detect them in the command, I just exit out with an error message?
How would I go about doing this?
I am using std::string. So maybe a list like !@#$%^&*()<><<>> etc., where I can detect and get out. I am not sure if there is an easier way to do this so Unix does not think I am giving it a system command when in fact it is just an input to a program, albeit it just happens to be a wrong/invalid input.
You can’t fix this by modifying your program — those special characters are being
interpreted by the shell before your code ever sees them.
You can prevent this by single-quoting the command-line argument:
or by escaping the special characters (by preceding each one with a backslash):