Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

底层数据库操作类lib/query.py的一些问题,探讨一下! #12

Open
mywaiting opened this issue Jan 24, 2015 · 1 comment
Open

Comments

@mywaiting
Copy link

        # update
        if(self.__check("data") and statement == "data:save"):
            sets = ""
            for data in self.__protected["__data"]:
                sets = sets + "%s = '%s', " % (data, self.__valuefix(self.__protected["__data"][data]))

            sets = sets.strip().rstrip(",")
            sql = sql + " SET %s" % sets

        # insert
        if(self.__check("data") and statement == "data:add"):
            sets = ""
            values = ""
            for data in self.__protected["__data"]:
                sets = sets + "%s, " % data
                values = values + "'%s', " % self.__valuefix(self.__protected["__data"][data])

            sets = sets.strip().rstrip(",")
            values = values.strip().rstrip(",")
            sql = sql + " (%s)" % sets
            sql = sql + " VALUES (%s)" % values

如上,当update或者insert的值是None的时候,照样被带入sql语句了,这样会导致数据库报错。

以update为例子,假设self.__protected["__data"][data]=None,那么就会生成语句update tablename set data = None where ...这样会让数据库报错!

修复方案:
应该先判断一下self.__protected["__data"][data]=None中的值是否为None,否则不执行下面的生成SQL的语句,insert操作处的修改也一样!

希望作者详细测试一下!

@mywaiting
Copy link
Author

另外,仔细看过一遍这个 lib/query.py 发现 SQL 语句是拼接式的,一不小心就会有 SQL注入啊

建议重新规划一下代码,改成 prepare statement 的形式

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant