Ejemplo n.º 1
0
static void NaClLoadIrt(struct NaClApp *nap, struct NaClDesc *irt_desc) {
  struct NaClRichFileInfo info;
  struct NaClValidationMetadata metadata;
  NaClErrorCode errcode;

  /* Attach file origin info to the IRT's NaClDesc. */
  NaClRichFileInfoCtor(&info);
  /*
   * For the IRT use a fake file name with null characters at the begining and
   * the end of the name.
   * TODO(ncbray): plumb the real filename in from Chrome.
   * Note that when the file info is attached to the NaClDesc, information from
   * stat is incorporated into the metadata.  There is no functional reason to
   * attach the info to the NaClDesc other than to create the final metadata.
   * TODO(ncbray): API for deriving metadata from a NaClDesc without attaching.
   */
  info.known_file = 1;
  info.file_path = kFakeIrtName;
  info.file_path_length = sizeof(kFakeIrtName);
  NaClSetFileOriginInfo(irt_desc, &info);
  /* Don't free the info struct because we don't own the file path string. */

  NaClMetadataFromNaClDescCtor(&metadata, irt_desc);
  errcode = NaClMainLoadIrt(nap, irt_desc, &metadata);
  if (errcode != LOAD_OK) {
    NaClLog(LOG_FATAL,
            "NaClLoadIrt: Failed to load the integrated runtime (IRT): %s\n",
            NaClErrorString(errcode));
  }

  NaClMetadataDtor(&metadata);
}
Ejemplo n.º 2
0
struct NaClDesc *NaClExchangeFileTokenForMappableDesc(
    struct NaClFileToken *file_token,
    struct NaClValidationCache *validation_cache) {
  int32_t new_fd;
  char *file_path;
  uint32_t file_path_length;
  struct NaClDesc *desc = NULL;

  /*
   * Not all file loading paths will produce a valid token.  Zero is
   * an invalid token value that indicates there is nothing to
   * resolve.  In this case, assume nothing about the providence of
   * the file.
   */
  if (!(file_token->lo == 0 && file_token->hi == 0) &&
      validation_cache->ResolveFileToken != NULL &&
      validation_cache->ResolveFileToken(validation_cache->handle,
                                         file_token,
                                         &new_fd,
                                         &file_path,
                                         &file_path_length)) {
    struct NaClRichFileInfo info;

    desc = NaClDescIoDescFromHandleAllocCtor((NaClHandle) new_fd,
                                             NACL_ABI_O_RDONLY);

    /* Mark the desc as OK for mmapping. */
    NaClDescMarkSafeForMmap(desc);

    /* Provide metadata for validation. */
    NaClRichFileInfoCtor(&info);
    info.known_file = 1;
    info.file_path = file_path;  /* Takes ownership. */
    info.file_path_length = file_path_length;
    NaClSetFileOriginInfo(desc, &info);
    NaClRichFileInfoDtor(&info);
  }
  return desc;
}
struct NaClDesc *NaClDescCreateWithFilePathMetadata(NaClHandle handle,
                                                    const char *file_path) {
  struct NaClDesc *desc = NaClDescIoDescFromHandleAllocCtor(handle,
                                                            NACL_ABI_O_RDONLY);
  char *alloc_file_path;
  size_t file_path_length = strlen(file_path);

  struct NaClRichFileInfo info;

  if (desc == NULL)
    return NULL;

  /*
   * If there is no file path metadata, just return the created NaClDesc
   * without adding rich file info.
   */
  if (file_path_length == 0)
    return desc;

  /* Mark the desc as OK for mmapping. */
  NaClDescMarkSafeForMmap(desc);

  alloc_file_path = (char *) malloc(file_path_length + 1);
  if (alloc_file_path == NULL) {
    NaClDescUnref(desc);
    return NULL;
  }
  memcpy(alloc_file_path, file_path, file_path_length + 1);

  /* Provide metadata for validation. */
  NaClRichFileInfoCtor(&info);
  info.known_file = 1;
  info.file_path = alloc_file_path;  /* Takes ownership. */
  info.file_path_length = (uint32_t) file_path_length;
  NaClSetFileOriginInfo(desc, &info);
  NaClRichFileInfoDtor(&info);
  return desc;
}