int SeekPastEndAndWriteTest(struct NaClHostDesc *test_file,
                            struct NaClHostDesc *ro_view,
                            void const *test_params) {
  nacl_host_stat_t stbuf;
  nacl_off64_t new_size;
  ssize_t io_err;
  int err;
  nacl_off64_t seek_result;

  UNREFERENCED_PARAMETER(test_params);
  err = NaClHostDescFstat(test_file, &stbuf);
  if (0 != err) {
    fprintf(stderr, "SeekPastEndAndWriteTest: fstat failed\n");
    return 0;
  }
  new_size = stbuf.st_size + (2 << 16);
  seek_result = NaClHostDescSeek(test_file, new_size, 0);
  if (seek_result != new_size) {
    fprintf(stderr, "SeekPastEndAndWriteTest: seek failed\n");
    return 0;
  }
  io_err = NaClHostDescWrite(test_file, "1", 1);
  if (1 != io_err) {
    fprintf(stderr, "SeekPastEndAndWriteTest: write failed: %"NACL_PRIdS"\n",
            io_err);
  }
  err = NaClHostDescFstat(test_file, &stbuf);
  if (0 != err) {
    fprintf(stderr, "SeekPastEndAndWriteTest: post-write fstat failed\n");
    return 0;
  }
  ASSERT_EQ(stbuf.st_size, new_size + 1);
  err = NaClHostDescFstat(ro_view, &stbuf);
  if (0 != err) {
    fprintf(stderr,
            "SeekPastEndAndWriteTest: post-write ro_view fstat failed\n");
    return 0;
  }
  ASSERT_EQ(stbuf.st_size, new_size + 1);
  return 1;
}
Beispiel #2
0
static int NaClDescIoDescFstat(struct NaClDesc         *vself,
                               struct nacl_abi_stat    *statbuf) {
  struct NaClDescIoDesc *self = (struct NaClDescIoDesc *) vself;
  int                   rv;
  nacl_host_stat_t      hstatbuf;

  rv = NaClHostDescFstat(self->hd, &hstatbuf);
  if (0 != rv) {
    return rv;
  }
  return NaClAbiStatHostDescStatXlateCtor(statbuf, &hstatbuf);
}
void NaClMetadataFromFDCtor(struct NaClValidationMetadata *metadata,
                            int file_desc,
                            const char* file_name,
                            size_t file_name_length) {
  struct NaClHostDesc wrapper;
  nacl_host_stat_t stat;
#if NACL_WINDOWS
  BY_HANDLE_FILE_INFORMATION file_info;
#endif

  memset(metadata, 0, sizeof(*metadata));
  /* If we early out, identity_type will be 0 / NaClCodeIdentityData. */

  wrapper.d = file_desc;
  if(NaClHostDescFstat(&wrapper, &stat))
    return;

#if NACL_WINDOWS
  /*
   * This will not get us the complete file ID on ReFS, but doing the correct
   * thing (calling GetFileInformationByHandleEx) causes linkage issues on
   * Windows XP.  We aren't relying on the file ID for security, just collision
   * resistance, so we don't need all of it.
   * In many cases (including on NTFS) we're also getting the 32 least
   * significant bits of a 64-bit volume serial number - but again, since it's
   * random we can live with it.
   */
  if (!GetFileInformationByHandle((HANDLE) _get_osfhandle(file_desc),
                                  &file_info))
    return;
  metadata->device_id = file_info.dwVolumeSerialNumber;
  metadata->file_id = ((((uint64_t)file_info.nFileIndexHigh) << 32) |
                       file_info.nFileIndexLow);
#else
  /* st_dev is not actually a property of the device, so skip it. */
  metadata->file_id = stat.st_ino;
#endif

  metadata->file_size = stat.st_size;
  metadata->mtime = stat.st_mtime;
  metadata->ctime = stat.st_ctime;

  CHECK(0 < file_name_length);
  metadata->file_name = malloc(file_name_length);
  CHECK(NULL != metadata->file_name);
  memcpy(metadata->file_name, file_name, file_name_length);
  metadata->file_name_length = file_name_length;

  /* We have all the identity information we need. */
  metadata->identity_type = NaClCodeIdentityFile;
}