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; }
/* * DEPRECATED, here for backwards compatibility. See header file for * details. */ struct NaClDesc *NaClDescIoDescMakeFromHandle(NaClHandle handle) { return NaClDescIoDescFromHandleAllocCtor(handle, NACL_ABI_O_RDWR); }