Merge pull request #160 from Team-LJY/fix/private-group-null-path
시험 보조 코드의 statx NULL 경로 처리 수정
- 작성자
- 코바야시
- 작성 시각
- 커밋
590bc45c86d8f72d790303e36312a68bfaefca66
변경된 파일 3개
+91-3| @@ -486,6 +486,42 @@ fn private_group_accepts_sss_only_without_socket_and_caches() { | ||
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | |
| 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 | 추가: | |
| 489 | 525 | fn shim() -> &'static PathBuf { |
| 490 | 526 | static LIBRARY: std::sync::OnceLock<(Scratch, PathBuf)> = std::sync::OnceLock::new(); |
| 491 | 527 | &LIBRARY |
| @@ -63,6 +63,9 @@ int getgrgid_r(gid_t gid, struct group *group, char *buffer, size_t length, | ||
| 63 | 63 | #include <sys/un.h> |
| 64 | 64 | |
| 65 | 65 | static const char *redirect(const char *path, char *buffer, size_t length) { |
| 66 | 추가: if (!path) { | |
| 67 | 추가: return path; | |
| 68 | 추가: } | |
| 66 | 69 | const char *base = NULL; |
| 67 | 70 | const char *tail = NULL; |
| 68 | 71 | if (!strncmp(path, "/var/lib/sss", 12) && (!path[12] || path[12] == '/')) { |
| @@ -94,17 +97,20 @@ static const char *redirect(const char *path, char *buffer, size_t length) { | ||
| 94 | 97 | return buffer; |
| 95 | 98 | } |
| 96 | 99 | |
| 97 | 삭제: int statx(int fd, const char *path, int flags, unsigned int mask, struct statx *info) { | |
| 100 | 추가: int private_group_statx(int fd, const char *path, int flags, unsigned int mask, | |
| 101 | 추가: struct statx *info) __asm__("statx"); | |
| 102 | 추가: | |
| 103 | 추가: int private_group_statx(int fd, const char *path, int flags, unsigned int mask, struct statx *info) { | |
| 98 | 104 | int (*original)(int, const char *, int, unsigned int, struct statx *) = dlsym(RTLD_NEXT, "statx"); |
| 99 | 105 | const char *phase = getenv("ZIPELO_GROUP_CASE"); |
| 100 | 삭제: if (phase && ((!strcmp(phase, "sss-probe-error") && !strncmp(path, "/var/lib/sss", 12)) || | |
| 106 | 추가: if (path && phase && ((!strcmp(phase, "sss-probe-error") && !strncmp(path, "/var/lib/sss", 12)) || | |
| 101 | 107 | (!strcmp(phase, "userdb-probe-error") && !strcmp(path, "/etc/userdb")))) { |
| 102 | 108 | errno = EACCES; |
| 103 | 109 | return -1; |
| 104 | 110 | } |
| 105 | 111 | char buffer[PATH_MAX]; |
| 106 | 112 | const char *mapped = redirect(path, buffer, sizeof(buffer)); |
| 107 | 삭제: return mapped ? original(fd, mapped, flags, mask, info) : -1; | |
| 113 | 추가: return mapped || !path ? original(fd, mapped, flags, mask, info) : -1; | |
| 108 | 114 | } |
| 109 | 115 | |
| 110 | 116 | DIR *opendir(const char *path) { |
| @@ -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 | 추가: } |