Skip to content

Commit e04d7d7

Browse files
refactor: add comment.
1 parent 745adf9 commit e04d7d7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

installer/sandbox.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ static int is_sandbox_user() {
8686
return 0;
8787
}
8888
/**
89-
* 匹配黑名单(用于域名或具体字符串匹配)
89+
* 限制网络访问
9090
*/
91-
static int match_env_patterns(const char *target, const char *env_val) {
91+
// ------------------ 匹配 域名 黑名单 ------------------
92+
static int match_banned_domain(const char *target, const char *env_val) {
9293
if (!target || !env_val || !*env_val) return 0;
9394
char *patterns = strdup(env_val);
9495
char *token = strtok(patterns, ",");
@@ -115,7 +116,7 @@ static int match_env_patterns(const char *target, const char *env_val) {
115116
free(patterns);
116117
return matched;
117118
}
118-
// ------------------ IP/CIDR 黑名单 ------------------
119+
// ------------------ 匹配 IP/CIDR 黑名单 ------------------
119120
static int match_banned_ip(const char *ip_str, const char *banned_list) {
120121
if (!ip_str || !banned_list || !*banned_list) return 0;
121122
char *list = strdup(banned_list);
@@ -186,15 +187,17 @@ int getaddrinfo(const char *node, const char *service,
186187
inet_pton(AF_INET6, node, &ipv6) == 1;
187188
if (!is_ip) {
188189
// 仅对域名进行阻塞
189-
if (match_env_patterns(node, banned_hosts)) {
190+
if (match_banned_domain(node, banned_hosts)) {
190191
fprintf(stderr, "[sandbox] 🚫 Access to host %s is banned (DNS blocked)\n", node);
191192
return EAI_FAIL;
192193
}
193194
}
194195
}
195196
return real_getaddrinfo(node, service, hints, res);
196197
}
197-
/* ------------------ 禁止创建子进程------------------ */
198+
/**
199+
* 限制创建子进程
200+
*/
198201
static int allow_create_subprocess() {
199202
ensure_config_loaded();
200203
return allow_subprocess || !is_sandbox_user();

0 commit comments

Comments
 (0)