title: Read file content in SGX enclave
body: <p>I'm trying to read the content of a file from an enclave using OCalls.</p>
  
  <p>enclave.edl:</p>
  
  <pre><code>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);
  };
  </code></pre>
  
  <p>enclave.cpp:</p>
  
  <pre><code>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, &amp;size);
  </code></pre>
  
  <p>implementation of ocall functions in the application:</p>
  
  <pre><code>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(&amp;tmp[0], &amp;tmp[9], content);
  
      cout &lt;&lt; content &lt;&lt; endl;
  }
  </code></pre>
  
  <p>But the result I receive is the following:</p>
  
  <blockquote>
    <p>123456789 (null)</p>
  </blockquote>
  
  <p>I'm not sure what I'm doing wrong?</p>