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

Function elf_check_ehdr

components/lwp/lwp_elf.c:269–304  ·  view source on GitHub ↗

* @brief Validate an ELF header. * * @param ehdr Pointer to the ELF header to validate. * @param file_len Length of the ELF file. * @return RT_EOK if valid, -RT_ERROR if invalid. */

Source from the content-addressed store, hash-verified

267 * @return RT_EOK if valid, -RT_ERROR if invalid.
268 */
269static rt_int32_t elf_check_ehdr(const Elf_Ehdr *ehdr, rt_uint32_t file_len)
270{
271 if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0)
272 {
273 LOG_E("%s : e_ident error", __func__);
274 return -RT_ERROR;
275 }
276
277 if ((ehdr->e_type != ET_EXEC) && (ehdr->e_type != ET_DYN))
278 {
279 LOG_E("%s : e_type error", __func__);
280 return -RT_ERROR;
281 }
282
283 if (ehdr->e_machine == EM_NONE)
284 {
285 LOG_E("%s : e_machine is EM_NONE", __func__);
286 return -RT_ERROR;
287 }
288
289 if (ehdr->e_phnum > ELF_PHDR_NUM_MAX)
290 {
291 LOG_E("%s : e_phnum error", __func__);
292 return -RT_ERROR;
293 }
294
295 if (ehdr->e_phoff > file_len)
296 {
297 LOG_E("%s : e_phoff error", __func__);
298 return -RT_ERROR;
299 }
300
301 LOG_D("%s : e_entry : 0x%x", __func__, ehdr->e_entry);
302
303 return RT_EOK;
304}
305
306/**
307 * @brief Validate an ELF program header.

Callers 1

elf_load_ehdrFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected