From e795b8a7ae584b93907942314c4c57eaa8beb26e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 3 Aug 2023 10:37:25 +0300 Subject: [PATCH] DynASM: Fix crash in dasm_encode() when some section is empty Fixes GH #1041 --- dynasm/dasm_arm.h | 1 + dynasm/dasm_arm64.h | 1 + dynasm/dasm_mips.h | 1 + dynasm/dasm_ppc.h | 1 + dynasm/dasm_x86.h | 1 + 5 files changed, 5 insertions(+) diff --git a/dynasm/dasm_arm.h b/dynasm/dasm_arm.h index aa16014e..3396769e 100644 --- a/dynasm/dasm_arm.h +++ b/dynasm/dasm_arm.h @@ -141,6 +141,7 @@ void dasm_setup(Dst_DECL, const void *actionlist) memset((void *)D->lglabels, 0, D->lgsize); if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); for (i = 0; i < D->maxsection; i++) { + D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); D->sections[i].pos = DASM_SEC2POS(i); D->sections[i].ofs = 0; } diff --git a/dynasm/dasm_arm64.h b/dynasm/dasm_arm64.h index e04898f1..9e4157f8 100644 --- a/dynasm/dasm_arm64.h +++ b/dynasm/dasm_arm64.h @@ -143,6 +143,7 @@ void dasm_setup(Dst_DECL, const void *actionlist) memset((void *)D->lglabels, 0, D->lgsize); if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); for (i = 0; i < D->maxsection; i++) { + D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); D->sections[i].pos = DASM_SEC2POS(i); D->sections[i].ofs = 0; } diff --git a/dynasm/dasm_mips.h b/dynasm/dasm_mips.h index 495eaa0e..8cb79052 100644 --- a/dynasm/dasm_mips.h +++ b/dynasm/dasm_mips.h @@ -140,6 +140,7 @@ void dasm_setup(Dst_DECL, const void *actionlist) memset((void *)D->lglabels, 0, D->lgsize); if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); for (i = 0; i < D->maxsection; i++) { + D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); D->sections[i].pos = DASM_SEC2POS(i); D->sections[i].ofs = 0; } diff --git a/dynasm/dasm_ppc.h b/dynasm/dasm_ppc.h index 30b757e3..71cd389d 100644 --- a/dynasm/dasm_ppc.h +++ b/dynasm/dasm_ppc.h @@ -140,6 +140,7 @@ void dasm_setup(Dst_DECL, const void *actionlist) memset((void *)D->lglabels, 0, D->lgsize); if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); for (i = 0; i < D->maxsection; i++) { + D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); D->sections[i].pos = DASM_SEC2POS(i); D->sections[i].ofs = 0; } diff --git a/dynasm/dasm_x86.h b/dynasm/dasm_x86.h index 66a68ea5..f16b3760 100644 --- a/dynasm/dasm_x86.h +++ b/dynasm/dasm_x86.h @@ -139,6 +139,7 @@ void dasm_setup(Dst_DECL, const void *actionlist) memset((void *)D->lglabels, 0, D->lgsize); if (D->pclabels) memset((void *)D->pclabels, 0, D->pcsize); for (i = 0; i < D->maxsection; i++) { + D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); D->sections[i].pos = DASM_SEC2POS(i); D->sections[i].ofs = 0; }