it's not correct to use MAXPATHNAME-sized buffer for link command, as

pointed out by Klaus Klein (original idea was that it should hold at least
the pathname ...); instead, let the ELF and a.out backends allocate memory
for the link command, and get rid of the fixed size buffer altogether
This commit is contained in:
jdolecek 2004-02-11 18:42:37 +00:00
parent bcdf1b194a
commit a09b055053
4 changed files with 22 additions and 32 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: a.out.c,v 1.4 2002/10/10 01:57:10 simonb Exp $ */
/* $NetBSD: a.out.c,v 1.5 2004/02/11 18:42:37 jdolecek Exp $ */
/*
* Copyright (c) 1993 Terrence R. Lambert.
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: a.out.c,v 1.4 2002/10/10 01:57:10 simonb Exp $");
__RCSID("$NetBSD: a.out.c,v 1.5 2004/02/11 18:42:37 jdolecek Exp $");
#include <sys/param.h>
#include <sys/ioctl.h>
@ -62,8 +62,7 @@ __RCSID("$NetBSD: a.out.c,v 1.4 2002/10/10 01:57:10 simonb Exp $");
#define LINKCMD "ld -A %s -e _%s -o %s -T %p %s"
void
a_out_linkcmd(char *buf,
size_t len,
a_out_linkcmd(char **cmdp,
const char *kernel,
const char *entry,
const char *outfile,
@ -71,12 +70,7 @@ a_out_linkcmd(char *buf,
const char *object,
const char *ldscript) /* XXX ignored on a.out */
{
ssize_t n;
n = snprintf(buf, len, LINKCMD, kernel, entry,
outfile, address, object);
if (n >= len)
errx(1, "link command longer than %lu bytes", (u_long)len);
asprintf(cmdp, LINKCMD, kernel, entry, outfile, address, object);
}
static int

View File

@ -1,4 +1,4 @@
/* $NetBSD: elf.c,v 1.15 2003/10/21 02:31:08 fvdl Exp $ */
/* $NetBSD: elf.c,v 1.16 2004/02/11 18:42:37 jdolecek Exp $ */
/*
* Copyright (c) 1998 Johan Danielsson <joda@pdc.kth.se>
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: elf.c,v 1.15 2003/10/21 02:31:08 fvdl Exp $");
__RCSID("$NetBSD: elf.c,v 1.16 2004/02/11 18:42:37 jdolecek Exp $");
#include <sys/param.h>
@ -332,8 +332,7 @@ elf_mod_sizes(int fd,
/* make a link command; XXX if data_offset above is non-zero, force
data address to be at start of text + offset */
void
elf_linkcmd(char *buf,
size_t len,
elf_linkcmd(char **cmdp,
const char *kernel,
const char *entry,
const char *outfile,
@ -341,30 +340,25 @@ elf_linkcmd(char *buf,
const char *object,
const char *ldscript)
{
ssize_t n;
if (ldscript == NULL) {
if (data_offset == 0)
n = snprintf(buf, len, LINKCMD, kernel, entry,
asprintf(cmdp, LINKCMD, kernel, entry,
outfile, address, object);
else
n = snprintf(buf, len, LINKCMD2, kernel, entry,
asprintf(cmdp, LINKCMD2, kernel, entry,
outfile, address,
(const char *)address + data_offset,
object);
} else {
if (data_offset == 0)
n = snprintf(buf, len, LINKSCRIPTCMD, ldscript, kernel,
asprintf(cmdp, LINKSCRIPTCMD, ldscript, kernel,
entry, outfile, address, object);
else
n = snprintf(buf, len, LINKSCRIPTCMD2, ldscript, kernel,
asprintf(cmdp, LINKSCRIPTCMD2, ldscript, kernel,
entry, outfile, address,
(const char *)address + data_offset,
object);
}
if (n >= len)
errx(1, "link command longer than %lu bytes", (u_long)len);
}
/* load a pre-linked module; returns entry point */

View File

@ -1,4 +1,4 @@
/* $NetBSD: modload.c,v 1.42 2004/02/10 12:30:22 jdolecek Exp $ */
/* $NetBSD: modload.c,v 1.43 2004/02/11 18:42:37 jdolecek Exp $ */
/*
* Copyright (c) 1993 Terrence R. Lambert.
@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: modload.c,v 1.42 2004/02/10 12:30:22 jdolecek Exp $");
__RCSID("$NetBSD: modload.c,v 1.43 2004/02/11 18:42:37 jdolecek Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -85,16 +85,16 @@ prelink(const char *kernel,
const char *object,
const char *ldscript)
{
char cmdbuf[MAXPATHLEN+1];
char *cmd;
int error = 0;
linkcmd(cmdbuf, sizeof(cmdbuf), kernel, entry, outfile, address,
linkcmd(&cmd, kernel, entry, outfile, address,
object, ldscript);
if (debug)
fprintf(stderr, "%s\n", cmdbuf);
fprintf(stderr, "%s\n", cmd);
switch (system(cmdbuf)) {
switch (system(cmd)) {
case 0: /* SUCCESS! */
break;
case 1: /* uninformitive error */
@ -114,6 +114,8 @@ prelink(const char *kernel,
break;
}
free(cmd);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: modload.h,v 1.5 2002/10/10 01:57:10 simonb Exp $ */
/* $NetBSD: modload.h,v 1.6 2004/02/11 18:42:37 jdolecek Exp $ */
/*
* Copyright (c) 1993 Terrence R. Lambert.
@ -37,14 +37,14 @@
int elf_mod_sizes(int, size_t *, int *, struct lmc_resrv *, struct stat *);
void *elf_mod_load(int);
void elf_linkcmd(char *, size_t, const char *, const char *, const char *,
void elf_linkcmd(char **, const char *, const char *, const char *,
const void *, const char *, const char *);
void elf_mod_symload(int);
int a_out_mod_sizes(int, size_t *, int *, struct lmc_resrv *,
struct stat *);
void *a_out_mod_load(int);
void a_out_linkcmd(char *, size_t, const char *, const char *, const char *,
void a_out_linkcmd(char **, const char *, const char *, const char *,
const void *, const char *, const char *);
void a_out_mod_symload(int);