Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“安全的在线测评”第一问的非预期解:直接读取 static.out 的内容 #43

Open
liginity opened this issue Oct 30, 2022 · 1 comment
Labels

Comments

@liginity
Copy link

出题人在打包 docker image 时把 data/ 目录用 COPY 加入了 image 中,并且设置目录拥有者为 judger,目录的权限是 766。

online_judge.py 中预期使用 os.makedir() 来设置 data 目录的权限为 700,但是 os.makedir() 不改变已存在的目录的权限,见 python 3.11 文档 os.makedirs。所以 runner 用户可以读取 data 中的内容。

static.out 是其他用户可读的。所以有下面的非预期解。

#include <stdio.h>
#include <stdlib.h>

// static_data_path
char *sdata_input_path = "./data/static.in";
char *sdata_output_path = "./data/static.out";

const int LEN = 2048;

int main() {
    char *lines[2];
    size_t ns[2];
    FILE *fp = fopen(sdata_output_path, "r");
    if (fp == NULL) {
        printf("failed to read static output");
        exit(1);
    }
    // read and show the 2 prime numbers.
    getline(&lines[0], &ns[0], fp);
    printf("%s", lines[0]);
    getline(&lines[1], &ns[0], fp);
    printf("%s", lines[1]);

    free(lines[0]);
    free(lines[1]);
    fclose(fp);
    return 0;
}
@taoky taoky added the solution label Oct 30, 2022
@mikualpha
Copy link

mikualpha commented Oct 30, 2022

我说怎么这题和杯窗鹅影第一题做法一模一样(甚至代码改个文件名交上去就PASS了),完全不像HG的出题风格,原来是非预期解……
然后成功把我带到按顺序输出的沟里了,代码糊完发现读不出dynamic一脸蒙圈0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants