如何设计一个安全沙盒

在 OJ 中,沙盒是必不可少的一环,服务器无法相信用户提交的代码,这可能导致很多安全问题。

总体上来说,沙盒需要做到两点:

  • 对系统调用进行限制
  • 对资源使用进行限制
Read more

使用GNU C扩展实现C的反射

说明:此机制并非传统意义上的反射,仅为一种类似的实现

我最近在写一个 Sandbox,需要根据命令行参数选择对应的规则函数执行。如果硬编码,这是非常痛苦的,所以我在 Google 搜了一会,发现了如下的办法,相比硬编码要好许多。

Read more

Simple C Implementation of HTTP Server

README

记录一下自己计算机网络课程设计作品

课题

Unix 下简易 HTTP 服务器的 C 语言实现

要求

使用 Berkeley Socket 实现基本的 TCP 通讯,并在此基础上遵循 HTTP 协议进行通讯

实现 HTTP/1.1 的基本功能,支持GET方法,支持访问静态内容,支持常见的MIME文件类型

Read more

为什么1/2=0?

C primer plus 课后作业 3.11.8

1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
int main(void)
{
int cup; //1cup=0.5pint=8ounce=16big=48small
printf("How many cups?\n");
scanf("%d",&cup);
printf("%d Cup is %f in pint,%d in ounce,%d in big and %d in small",cup, cup/2, cup*8, cup*16, cup*48);
}
//output: 1 Cup is 0 in pint,8 in ouns,16 in big and 48 in small
//cup/2改成cup*0.5
//output: 1 Cup is 0.500000 in pint,8 in ounce,16 in big and 48 in small

查阅发现
C 的除法,当两边都是整型值时,做整数除法,得到的也是整数,并会对形如5/3的运算结果做截断处理,并且不四舍五入

如果两边至少有一个为 float 或者 double,那么将做浮点数除法,1.0/2=0.5 。

C 并不推荐这种混合类型的除法运算,因为计算机原理上无法做到浮点数除以整数的运算。用浮点数除以整数时,C 编译器只是将整数转换为了浮点数

1
2
3
    float c=2.0;
printf("%f",cup/c);
//output : 0.500000
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×