HLab-SW安全编程规范 考试 在线考试 答题题目
1、 一下代码段哪里不符合规范?
int VerifyPassword(string password)
{
//内容省略
}
int Func()
{
string password = GetPassword();
VerifyPassword(password);
...
}
2、 下面描述错误的是?
3、 关于下面代码段的描述,错误的是?
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
enum { BUFFERSIZE = 512 };
void func(const char *input) {
char cmdbuf[BUFFERSIZE];
int len_wanted = snprintf(cmdbuf, BUFFERSIZE,
"any_cmd '%s'", input);
if (len_wanted >= BUFFERSIZE) {
/* Handle error */
} else if (len_wanted < 0) {
/* Handle error */
} else if (system(cmdbuf) == -1) {
/* Handle error */
}
}
4、 下面代码段的描述,哪个不符合Hlab-SW安全编程规范?
void host_lookup(char *user_supplied_addr)
{
struct hostent *hp;
in_addr_t *addr;
char hostname[64];
in_addr_t inet_addr(const char *cp);
/* routine that ensures user_supplied_addr is in the right format for conversion */
validate_addr_form(user_supplied_addr);
addr = inet_addr(user_supplied_addr);
hp = gethostbyaddr(addr, sizeof(struct in_addr), AF_INET);
strcpy(hostname, hp->h_name);
}
5、 下面关于realloc()函数的描述,错误的是?
6、 悬挂指针可能会导致双重释放(double-free)以及访问已释放内存的危险。关于悬空指针的描述错误的是?
7、 下面哪个POSIX接口函数不能在信号处理程序中调用?
8、 下面关于“禁止引用未初始化的内存”规则的描述正确的是?
9、 关于“内存分配后必须判断是否成功”规则描述正确的是?
10、 在编程时遇到内存申请,Hlab人应该怎么做?
11、(多选题) 关于下面打开文件的操作正确的是:
char *fileName = GetMsgFromRemote();
...
sprintf_s(untrustPath, sizeof(untrustPath), "/tmp/%s", fileName);
char *text = ReadFileContent(untrustPath);
int fd = open(fileName, O_CREAT | O_WRONLY);
12、(多选题) 以下是经过修改的网络设备收包处理流程代码,其中违背了哪些安全编程规则?
void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask)
{
void *data;
fragsz = SKB_DATA_ALIGN(fragsz);
if (in_hardirq() || irqs_disabled()) {
struct page_frag_cache *nc = this_cpu_ptr(&netdev_alloc_cache);
data = page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, align_mask);
if (data == NULL) {
schedule();
}
} else if (in_softirq()) {
delay();
} else {
struct napi_alloc_cache *nc;
local_bh_disable();
nc = this_cpu_ptr(&napi_alloc_cache);
data = page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask);
local_bh_enable();
}
return data;
}
13、(多选题) 关于下面代码,描述正确的是:
char *log_message;
void Handler(int signum) {
syslog(LOG_NOTICE, "%s\n", log_m_essage);
free(log_message);
sleep(10);
exit(0);
}
int main (int argc, char* argv[]) {
log_message = strdup(argv[1]);
signal(SIGHUP, Handler);
signal(SIGTERM, Handler);
sleep(10);
}
14、(多选题) 对字符串或数组进行操作时,下面哪些描述是符合安全规范的?
15、(多选题) 线程是调度的最小单元。下面对进程线程的操作不符合规范的是?
16、(多选题) 下面对C++类的操作哪些是不符合规范要求的?
17、(多选题) 对下面代码的描述,正确的是?
void OsTask()
{
...
while (true) {
msgHdl = receive(OS_WAIT_FOREVER, &msgId, &senderPid);
if (msgHdl == 0) {
continue;
}
switch (msgId) {
...
}
(void)free(msgHdl);
msgHdl = NULL;
}
}
18、(多选题) 对下面代码的评价符合安全规范的是?
char *message;
...
if (condition) {
message = (char *)malloc(len);
...
}
...
if (message != NULL) {
memset (message, 0, sizeof(message));
...
free(message);
}
19、(多选题) 下面的代码,存在哪些风险?
#define MAX_BUFF 0x1000000
int Foo(void)
{
int buff[MAX_BUFF] = {0};
size_t width = ReadByte();
size_t height = ReadByte();
size_t a = ReadByte();
size_t total = width * height;
void *bitmaps = (void *)malloc(total);
size_t b = 1000 / a;
size_t c = 1000 % a;
...
//省略后续处理
}
20、(多选题) Hlab-SW对整数编程的要求有哪些?
微信扫一扫 在线答题 在线出卷 随机出题小程序 闯关答题软件 出题答题小程序