MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / elf_check_phdr

Function elf_check_phdr

components/lwp/lwp_elf.c:312–335  ·  view source on GitHub ↗

* @brief Validate an ELF program header. * * @param phdr Pointer to the ELF program header to validate. * @return RT_EOK if valid, -RT_ERROR if invalid. */

Source from the content-addressed store, hash-verified

310 * @return RT_EOK if valid, -RT_ERROR if invalid.
311 */
312static int elf_check_phdr(const Elf_Phdr *phdr)
313{
314 if (phdr->p_filesz > FILE_LENGTH_MAX)
315 {
316 LOG_E("%s : phdr p_filesz 0x%x error", __func__, phdr->p_filesz);
317 return -RT_ERROR;
318 }
319
320 if (phdr->p_offset > FILE_LENGTH_MAX)
321 {
322 LOG_E("%s : phdr p_offset 0x%x error", __func__, phdr->p_offset);
323 return -RT_ERROR;
324 }
325
326 if (phdr->p_memsz > MEM_SIZE_MAX)
327 {
328 LOG_E("%s[%d], phdr p_memsz 0x%x error", __func__, phdr->p_memsz);
329 return -RT_ERROR;
330 }
331
332 LOG_D("%s : phdr p_vaddr : 0x%x", __func__, phdr->p_vaddr);
333
334 return RT_EOK;
335}
336
337/**
338 * @brief Load and validate the ELF header from a file.

Callers 2

elf_load_interpFunction · 0.85
elf_file_mmapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected