team-ljyzipelo

공개

시험 보조 코드의 statx NULL 경로 처리 수정

작성자
코노모리 카논
작성 시각
커밋
d184f280bd473f2c06953a918f7bcf9a2f325406
부모
f012101
이 시점의 파일 보기

변경된 파일 3개

+87-2
수정tests/rust-archive-worker/private_group.rs+36-0
@@ -486,6 +486,42 @@ fn private_group_accepts_sss_only_without_socket_and_caches() {
486486 }
487487}
488488
489추가: #[test]
490추가: fn private_group_shim_preserves_statx_null_and_empty_paths() {
491추가: let scratch = Scratch::new();
492추가: let probe = scratch.0.join("statx-path-probe");
493추가: assert!(
494추가: Command::new("cc")
495추가: .args(["-O2", "-Wall", "-Wextra", "-Werror"])
496추가: .arg(
497추가: PathBuf::from(env!("CARGO_MANIFEST_DIR"))
498추가: .join("../../tests/rust-archive-worker/private_group_statx.c")
499추가: )
500추가: .args(["-ldl", "-o"])
501추가: .arg(&probe)
502추가: .status()
503추가: .unwrap()
504추가: .success()
505추가: );
506추가: for case in [None, Some("sss-probe-error"), Some("userdb-probe-error")] {
507추가: let mut command = Command::new(&probe);
508추가: command
509추가: .env("LD_PRELOAD", shim())
510추가: .env_remove("ZIPELO_GROUP_CASE");
511추가: if let Some(case) = case {
512추가: command.env("ZIPELO_GROUP_CASE", case);
513추가: }
514추가: let result = command.output().unwrap();
515추가: assert!(
516추가: result.status.success(),
517추가: "case={case:?} status={:?}: {} {}",
518추가: result.status,
519추가: String::from_utf8_lossy(&result.stdout),
520추가: String::from_utf8_lossy(&result.stderr)
521추가: );
522추가: }
523추가: }
524추가:
489525fn shim() -> &'static PathBuf {
490526 static LIBRARY: std::sync::OnceLock<(Scratch, PathBuf)> = std::sync::OnceLock::new();
491527 &LIBRARY
수정tests/rust-archive-worker/private_group_nss.c+5-2
@@ -63,6 +63,9 @@ int getgrgid_r(gid_t gid, struct group *group, char *buffer, size_t length,
6363#include <sys/un.h>
6464
6565static const char *redirect(const char *path, char *buffer, size_t length) {
66추가: if (!path) {
67추가: return path;
68추가: }
6669 const char *base = NULL;
6770 const char *tail = NULL;
6871 if (!strncmp(path, "/var/lib/sss", 12) && (!path[12] || path[12] == '/')) {
@@ -97,14 +100,14 @@ static const char *redirect(const char *path, char *buffer, size_t length) {
97100int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *info) {
98101 int (*original)(int, const char *, int, unsigned int, struct statx *) = dlsym(RTLD_NEXT, "statx");
99102 const char *phase = getenv("ZIPELO_GROUP_CASE");
100삭제: if (phase && ((!strcmp(phase, "sss-probe-error") && !strncmp(path, "/var/lib/sss", 12)) ||
103추가: if (path && phase && ((!strcmp(phase, "sss-probe-error") && !strncmp(path, "/var/lib/sss", 12)) ||
101104 (!strcmp(phase, "userdb-probe-error") && !strcmp(path, "/etc/userdb")))) {
102105 errno = EACCES;
103106 return -1;
104107 }
105108 char buffer[PATH_MAX];
106109 const char *mapped = redirect(path, buffer, sizeof(buffer));
107삭제: return mapped ? original(fd, mapped, flags, mask, info) : -1;
110추가: return mapped || !path ? original(fd, mapped, flags, mask, info) : -1;
108111}
109112
110113DIR *opendir(const char *path) {
추가tests/rust-archive-worker/private_group_statx.c+46-0
@@ -0,0 +1,46 @@
1추가: #define _GNU_SOURCE
2추가: #include <dlfcn.h>
3추가: #include <errno.h>
4추가: #include <fcntl.h>
5추가: #include <stdio.h>
6추가: #include <sys/stat.h>
7추가: #include <unistd.h>
8추가:
9추가: typedef int (*statx_function)(int, const char *, int, unsigned int, struct statx *);
10추가:
11추가: int main(void) {
12추가: void *libc = dlopen("libc.so.6", RTLD_NOW);
13추가: if (!libc) return 1;
14추가: statx_function original = dlsym(libc, "statx");
15추가: statx_function intercepted = dlsym(RTLD_DEFAULT, "statx");
16추가: if (!original || !intercepted || original == intercepted) return 1;
17추가: int fd = open(".", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
18추가: if (fd < 0) return 1;
19추가: const char *paths[] = {NULL, "", "."};
20추가: const int flags[] = {0, AT_EMPTY_PATH};
21추가: int result = 0;
22추가: for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
23추가: for (size_t j = 0; j < sizeof(flags) / sizeof(flags[0]); j++) {
24추가: struct statx expected = {0};
25추가: struct statx actual = {0};
26추가: errno = 0;
27추가: int expected_result = original(fd, paths[i], flags[j], STATX_BASIC_STATS, &expected);
28추가: int expected_errno = errno;
29추가: errno = 0;
30추가: int actual_result = intercepted(fd, paths[i], flags[j], STATX_BASIC_STATS, &actual);
31추가: int actual_errno = errno;
32추가: if (actual_result != expected_result || actual_errno != expected_errno ||
33추가: (actual_result == 0 && (actual.stx_mask != expected.stx_mask ||
34추가: actual.stx_mode != expected.stx_mode || actual.stx_ino != expected.stx_ino ||
35추가: actual.stx_size != expected.stx_size))) {
36추가: fprintf(stderr, "path=%s flags=%d: result=%d errno=%d, expected result=%d errno=%d\n",
37추가: paths[i] ? paths[i] : "NULL", flags[j], actual_result, actual_errno,
38추가: expected_result, expected_errno);
39추가: result = 1;
40추가: }
41추가: }
42추가: }
43추가: close(fd);
44추가: dlclose(libc);
45추가: return result;
46추가: }