But still you wouldn't say that every software written in C is automatically insecure. You have to look into the actual case. Just grepping for SQL-string-concatination or uses of sprintf doesn't say much.
But still you wouldn't say that every software written in C is automatically insecure. You have to look into the actual case. Just grepping for SQL-string-concatination or uses of sprintf doesn't say much.
With sql that's different, every sane sql client library supports some form of prepared statements out of the box and they are really simple to use. There is no reason whatsoever to do this by hand, except for people that don't know better.
Prepared statements work fine as long as you just have simple SELECT statements with a few WHERE values as parameters. They completely fail if you need to do any advanced SQL with anything dynamic. Like optionally add more sophisticated calculated properties to the SELECT fields, conditionally JOIN in extra tables, use any of the DB engine's more advanced XML or JSON parsing features in a conditional way, support choosing <, > or =, etc.
this is true
> they are really simple to use
this is not. The amount of boilerplate I've written to properly parameterize a common pattern like
SELECT * FROM FOO WHERE
FOO.SomeKey IN (/* user-provided list of chosen values goes here */)
is grotesque. list = ['bar', 'baz', "Robert'); DROP TABLE Students;--"]
Foo.where(name: list)
# Foo Load (0.3ms)
# SELECT "foo".* FROM "foo"
# WHERE "foo"."name" IN (?, ?, ?)
# [["name", "bar"],
# ["name", "baz"],
# ["name", "Robert'); DROP TABLE Students;--"]] params = ", ".join(["?"] * count)
template = "SELECT ... WHERE foo in (%s)" % (params)
# proceed to prepare a statement from the query template
2) use a subquery, insert data somewhere if necessary SELECT ... WHERE foo in (SELECT foo FROM foos WHERE some_value = 42)
3) if the maximum number of parameters is low, you can keep it variable by enabling parts of the query with boolean parameters: SELECT ... WHERE (test_param1 AND foo = param1)
OR (test_param2 AND foo = param2)
OR (test_param3 AND foo = param3)