,由于我无法像usuall一样在安全解释器中加载套件,因此我将包命令与这样的安全解释器相似:
:set $safeInterp [safe::interpCreate]
$safeInterp alias package package
$safeInterp eval {package require sqlite3}
##After that, I executed
$safeInterp eval {sqlite3 db hello.sqlite3}
##But it failed and shows an error: invalid command name "sqlite3"
##So I alias the sqlite3 command, and connect to the database.
$safeInterp alias sqlite3 sqlite3
$safeInterp eval {sqlite3 db hello.sqlite3}
##But then even the db function cannot be found in safe interpreter.
我想知道是否有任何方法可以加载sqlite3软件包并在安全解释器中创建连接,因此我不需要别名主解释器中的每个命令。
tclsqlite
软件包确实故意不能定义安全的入口点,如源代码中所述。当将软件包加载到安全解释器中以提供更安全的命令子集时,使用_safeinit((而不是_init((。
/* Because it accesses the file-system and uses persistent state, SQLite
** is not considered appropriate for safe interpreters. Hence, we cause
** the _SafeInit() interfaces return TCL_ERROR.
*/
EXTERN int Sqlite3_SafeInit(Tcl_Interp *interp){ return TCL_ERROR; }
EXTERN int Sqlite3_SafeUnload(Tcl_Interp *interp, int flags){return TCL_ERROR;}
(来自https://www.sqlite.org/src/artifact/916a92de77ec5cbe(
简单地将sqlite命令与安全的解释器相混杂可能会使它不安全,尤其是如果某些额外的选项(例如可加载的模块(。
。所以不,不可能简单地将其加载而无需混音。为了使其安全,您可能应该添加一些策略包装器,以消毒命令并限制可用选项,具体取决于您的安全需求。