kyle has asked for the wisdom of the Perl Monks concerning the following question:
Say I have a variable, $suspicious, and I want to know if at some point someone said $suspicious = $dbh->quote( $clearly_tainted ) or if, sadly, $suspicous = $clearly_tainted.
The DBI documentation says that quote() may legally "return an SQL expression that evaluates to the desired string", so I can't simply test whether $suspicious "starts and ends with quotes and has all quotes inside escaped". Not only that, different databases may need things quoted differently anyway. I might also expect a special case for "NULL", which is a legal value without the quotes.
I suspect I may have to look into the DBD code for the particular database I'm using and write a way to detect whether a particular string could have come from it. This will break, however, when I'm connected to a different database.
(The XY Problem here, if you're curious, is that I may inherit some code that does not consistently quote() and use placeholders. This may lead me to do a lot of work tracing a variable from its use in some SQL back to its origin. I'm wondering if I can instead just put a sanity check in the place where it gets used. I don't actually have this problem now, but I'm trying to think ahead.)
I offer advanced thanks for your advanced wisdom.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can I tell if DBI's quote() was used?
by Joost (Canon) on Apr 06, 2008 at 15:49 UTC | |
by kyle (Abbot) on Apr 06, 2008 at 19:44 UTC | |
by Joost (Canon) on Apr 06, 2008 at 19:52 UTC | |
by kyle (Abbot) on Apr 06, 2008 at 20:10 UTC | |
|
Re: Can I tell if DBI's quote() was used?
by ikegami (Patriarch) on Apr 06, 2008 at 09:16 UTC | |
by kyle (Abbot) on Apr 06, 2008 at 19:44 UTC | |
by ikegami (Patriarch) on Apr 07, 2008 at 03:09 UTC | |
|
Re: Can I tell if DBI's quote() was used?
by Cabrion (Friar) on Apr 06, 2008 at 10:45 UTC | |
|
Re: Can I tell if DBI's quote() was used?
by stiller (Friar) on Apr 06, 2008 at 08:53 UTC | |
|
Re: Can I tell if DBI's quote() was used?
by bart (Canon) on Apr 08, 2008 at 07:46 UTC |