From 97ea77334836d11778333b9835a8604b9bd1beae Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 19 Oct 2005 07:18:20 +0000 Subject: [PATCH] * elf-x86-amd64.c (elf_x86_amd64_write_reloc): Fix a crash with ELF: when an invalid relocation is generated, this still gets called but with a NULL addend. * expr.c (expr_xform_bc_dist): Check return value of yasm_symrec_get_label() to avoid crash. svn path=/trunk/yasm/; revision=1288 --- libyasm/expr.c | 3 ++- modules/objfmts/elf/elf-x86-amd64.c | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libyasm/expr.c b/libyasm/expr.c index c989ce03..984c1c8d 100644 --- a/libyasm/expr.c +++ b/libyasm/expr.c @@ -221,7 +221,8 @@ expr_xform_bc_dist(/*@returned@*/ /*@only@*/ yasm_expr *e, if (!yasm_intnum_is_neg1(intn)) continue; - yasm_symrec_get_label(sym, &precbc); + if (!yasm_symrec_get_label(sym, &precbc)) + continue; sect2 = yasm_bc_get_section(precbc); /* Now look for a symrec term in the same segment */ diff --git a/modules/objfmts/elf/elf-x86-amd64.c b/modules/objfmts/elf/elf-x86-amd64.c index a8c62031..4a018c04 100644 --- a/modules/objfmts/elf/elf-x86-amd64.c +++ b/modules/objfmts/elf/elf-x86-amd64.c @@ -178,7 +178,12 @@ elf_x86_amd64_write_reloc(unsigned char *bufp, elf_reloc_entry *reloc, YASM_WRITE_64I_L(bufp, reloc->reloc.addr); /*YASM_WRITE_64_L(bufp, ELF64_R_INFO(r_sym, r_type));*/ YASM_WRITE_64C_L(bufp, r_sym, r_type); - YASM_WRITE_64I_L(bufp, reloc->addend); + if (reloc->addend) + YASM_WRITE_64I_L(bufp, reloc->addend); + else { + YASM_WRITE_32_L(bufp, 0); + YASM_WRITE_32_L(bufp, 0); + } } static void -- 2.40.0