commit f73976bc3b2384aae0124998f5746eb8f84677dd
parent 42a7e083ac9e2c901944975a21bf3b1f0d5674d6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sat, 18 Jan 2025 14:03:35 +0100
libmach/coff32: Fix reading line info
This part of the code was not tested ever, and there were
many wrong things, like the definition of the own structure
for lines.
Diffstat:
3 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/include/bits/scc/coff32/linenum.h b/include/bits/scc/coff32/linenum.h
@@ -1,8 +1,10 @@
/* This file is inspired in the book "Understanding and using COFF" */
struct lineno {
- long l_symndx; /* index in table symbol if l_lnno == 0 */
- long l_paddr; /* Break pointable address if l_lnno > 0 */
+ union {
+ long l_symndx; /* index in table symbol if l_lnno == 0 */
+ long l_paddr; /* Break pointable address if l_lnno > 0 */
+ } l_addr;
unsigned short l_lnno; /* Line number */
};
diff --git a/src/libmach/coff32/coff32read.c b/src/libmach/coff32/coff32read.c
@@ -35,9 +35,8 @@ unpack_line(int order, unsigned char *buf, LINENO *lp)
n = unpack(order,
buf,
- "lls",
- &lp->l_symndx,
- &lp->l_paddr,
+ "ls",
+ &lp->l_addr.l_symndx,
&lp->l_lnno);
assert(n == LINESZ);
}
@@ -448,7 +447,7 @@ static int
readlines(Obj *obj, FILE *fp)
{
int i,j;
- LINENO **lines, *lp;
+ LINENO **lines, *lp, *p;
FILHDR *hdr;
SCNHDR *scn;
struct coff32 *coff;
@@ -475,14 +474,18 @@ readlines(Obj *obj, FILE *fp)
return 0;
lines[i] = lp;
+ if (!objpos(obj, fp, scn->s_lnnoptr))
+ return 0;
+
for (j = 0; j < scn->s_nlnno; j++) {
- if (!objpos(obj, fp, scn->s_lnnoptr))
- return 0;
- if (fread(buf, LINESZ, 1, fp) == 1)
+ if (fread(buf, LINESZ, 1, fp) != 1)
return 0;
- unpack_line(ORDER(obj->type), buf, &lp[j]);
- if (lp[i].l_symndx >= hdr->f_nsyms)
+ unpack_line(ORDER(obj->type), buf, lp);
+ if (lp->l_lnno != 0
+ && lp->l_addr.l_symndx >= hdr->f_nsyms) {
return 0;
+ }
+ ++lp;
}
}
diff --git a/src/libmach/coff32/coff32write.c b/src/libmach/coff32/coff32write.c
@@ -204,8 +204,7 @@ pack_line(int order, unsigned char *buf, LINENO *lp)
n = pack(order,
buf,
"lls",
- lp->l_symndx,
- lp->l_paddr,
+ lp->l_addr.l_symndx,
lp->l_lnno);
assert(n == LINESZ);
}