问题描述
我正在尝试编写一个简单的判断器,该编译器将编译并执行用户提交的c文件.我发现 libsandbox 和一个问题 在 stackoverflow 上.
I'm trying to write a simple judge that will compile and execute user submitted c files. I found libsandbox and a question here on stackoverflow.
我已经安装了python模块,并按照说明尝试运行用C编写的hello world程序.
I have installed the python module and as per the instructions I'm trying to run a hello world program written in C
➜ sandbox git:(V_0_3_x) ✗ ./hello
Hello World%
➜ sandbox git:(V_0_3_x) ✗ python sample2.py hello
result: RF
cpu: 2ms
mem: 288kB
如您所见,当我在沙箱中运行程序时,没有任何输出.如果有人能告诉我如何正确使用它,那就太好了.
As you can see, when I run the program in the sandbox I don't get any output. It'd be great if someone could tell me how to correctly use it.
推荐答案
libsandbox
的示例代码禁止系统调用文件操作,例如 open()
, stat()
, close()
.也就是说,您需要(1)链接 hello world程序静态,以避免打开诸如共享库之类的文件(即 libc.so
),或 (2) 编写允许相关系统调用的自定义沙箱策略.有关自定义沙箱策略的一些示例可以在 https://github.com/liuyu81/TR-OJA中找到-201209A.
The sample code of libsandbox
forbids system calls for file operations, such as open()
, stat()
, close()
. That said, you'll need to either (1) link the hello world program statically to avoid opening files such as shared libraries (i.e. libc.so
), or (2) write a customized sandbox policy that permits relevant system calls. Some examples on customizing sandbox policies can be found at https://github.com/liuyu81/TR-OJA-201209A.
免责声明:我是 libsandbox
的作者.
DISCLAIMER: I am the author of libsandbox
.
这篇关于我如何开始使用libsandbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!