0

OCalls を使用してエンクレーブからファイルの内容を読み込もうとしています。

enclave.edl:

untrusted {
        void ocall_print_string([in, string] const char *str);
        void ocall_read_IMA_file([in, string] const char *filename, [out] char *buf, [out] int *size);
};

enclave.cpp:

void printf(const char *fmt, ...) {
    ocall_print_string(fmt);
}

void read_IMA_file(const char *filename, char *buf, int *size) {
    ocall_read_IMA_file(filename, buf, size);

    printf(buf);
}

//whereas the read_IMA_file function is called with
char *buf;
int size;
read_IMA_file("test.txt", buf, &size);

アプリケーションでの ocall 関数の実装:

void ocall_print_string(const char *str) {
    printf("%s\n", str);
}

void ocall_read_IMA_file(const char *filename, char *content, int *size) {
    content = (char*) malloc(sizeof(char) * 10);
    memset(content, '\0', sizeof(char) *10);
    char tmp[] = "1234567890";
    copy(&tmp[0], &tmp[9], content);

    cout << content << endl;
}

しかし、私が受け取る結果は次のとおりです。

123456789 (ヌル)

何が間違っているのかわかりませんか?

4

2 に答える 2

1

1234567890 を出力すると予想される場合は、malloc(10) の代わりに malloc(11) が必要になる可能性があります。また、copy の使用方法にもバグが含まれている可能性があります。

copy(&tmp[0], &tmp[9], コンテンツ); 123456789 をコンテンツにコピーしています。私が理解しているように、最後のイテレータ &tmp[9] を除外します。詳細については、http ://www.cplusplus.com/reference/algorithm/copy/ を参照してください。

また、ファイル「test.txt」からのコンテンツも読み込んでいないと思います。

于 2017-01-09T06:25:27.503 に答える