scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 7d51a01bf4af2dabf73154251864a977bac40bba
parent b8466e1b84611b8e5c6b6de35b47e5c62ee927b4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  5 Mar 2018 21:52:30 +0100

[nm] Extrace correct name of archive members

Diffstat:
Minc/ar.h | 4+++-
Mnm/main.c | 18++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/inc/ar.h b/inc/ar.h @@ -2,9 +2,11 @@ #define ARMAG "!<arch>\n" /* ar "magic number" */ #define SARMAG 8 /* strlen(ARMAG); */ #define ARFMAG "`\n" +#define SARNAM 16 + struct ar_hdr { - char ar_name[16]; /* name */ + char ar_name[SARNAM]; /* name */ char ar_date[12]; /* modification time */ char ar_uid[6]; /* user id */ char ar_gid[6]; /* group id */ diff --git a/nm/main.c b/nm/main.c @@ -39,11 +39,26 @@ archive(char *fname, FILE *fp) return strncmp(magic, ARMAG, SARMAG) == 0; } +static char * +getfname(struct ar_hdr *hdr, char *dst) +{ + char *p; + + memcpy(dst, hdr->ar_name, SARNAM); + dst[SARNAM] = '\0'; + if ((p = strchr(dst, ' ')) != NULL) + *p = '\0'; + if ((p = strchr(dst, '/')) != NULL) + *p = '\0'; + return (*p == '\0') ? NULL : dst; +} + static void ar(char *fname, FILE *fp) { struct ar_hdr hdr; long pos, siz; + char member[SARNAM+1]; arflag = 1; fseek(fp, sizeof(struct ar_hdr), SEEK_CUR); @@ -53,6 +68,9 @@ ar(char *fname, FILE *fp) if (strncmp(hdr.ar_fmag, ARFMAG, strlen(ARFMAG))) goto corrupted; + if (!getfname(&hdr, member)) + goto corrupted; + siz = 0; sscanf(hdr.ar_size, "%10ld", &siz); if (siz == 0)