summaryrefslogtreecommitdiffstats
path: root/usr.sbin/config
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2017-09-27 15:14:51 +0000
committerderaadt <deraadt@openbsd.org>2017-09-27 15:14:51 +0000
commit69574fe5a7e2132f260f0b83a4f64b777c3e606c (patch)
treebb6b3f7b263368c63e3b3c8e8969a7c606f82298 /usr.sbin/config
parentDocument how ioctl(2) LIOCSFD on /dev/klog registers a socket pair (diff)
downloadwireguard-openbsd-69574fe5a7e2132f260f0b83a4f64b777c3e606c.tar.xz
wireguard-openbsd-69574fe5a7e2132f260f0b83a4f64b777c3e606c.zip
config -e's adds new devices to an extra locator array, which is accounted
using a variable which started at 0 and hence got planted in .bss. Refactor that variable to begin at the maximum and decrease, such that it lands in .data instead. ok jsg
Diffstat (limited to 'usr.sbin/config')
-rw-r--r--usr.sbin/config/mkioconf.c8
-rw-r--r--usr.sbin/config/ukc.c8
-rw-r--r--usr.sbin/config/ukc.h14
-rw-r--r--usr.sbin/config/ukcutil.c52
4 files changed, 43 insertions, 39 deletions
diff --git a/usr.sbin/config/mkioconf.c b/usr.sbin/config/mkioconf.c
index 39eba11a776..9d6c419395a 100644
--- a/usr.sbin/config/mkioconf.c
+++ b/usr.sbin/config/mkioconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkioconf.c,v 1.36 2016/10/27 14:33:30 tb Exp $ */
+/* $OpenBSD: mkioconf.c,v 1.37 2017/09/27 15:14:51 deraadt Exp $ */
/* $NetBSD: mkioconf.c,v 1.41 1996/11/11 14:18:49 mycroft Exp $ */
/*
@@ -181,9 +181,9 @@ static long loc[%d] = {", locators.used) < 0)
return (fprintf(fp, "\n#ifndef MAXEXTRALOC\n\
#define MAXEXTRALOC 32\n\
#endif\n\
-long extraloc[MAXEXTRALOC] = { -1 };\n\
-int nextraloc = MAXEXTRALOC;\n\
-int uextraloc = 0;\n") < 0);
+long extraloc[MAXEXTRALOC] = { -1 }; /* extra locator space */\n\
+int rextraloc = MAXEXTRALOC; /* remaining extra locators */\n\
+const int textraloc = MAXEXTRALOC; /* total extra relocators */\n") < 0);
}
static int nlocnames, maxlocnames = 8;
diff --git a/usr.sbin/config/ukc.c b/usr.sbin/config/ukc.c
index ffc97d8176e..205a26c01f4 100644
--- a/usr.sbin/config/ukc.c
+++ b/usr.sbin/config/ukc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ukc.c,v 1.22 2016/10/19 16:39:02 tb Exp $ */
+/* $OpenBSD: ukc.c,v 1.23 2017/09/27 15:14:52 deraadt Exp $ */
/*
* Copyright (c) 1999-2001 Mats O Jansson. All rights reserved.
@@ -115,9 +115,9 @@ ukc(char *file, char *outfile, int uflag, int force)
if (force == 0 && outfile == NULL)
printf("WARNING no output file specified\n");
- if (nl[IA_EXTRALOC].n_type == 0 || nl[I_NEXTRALOC].n_type == 0 ||
- nl[I_UEXTRALOC].n_type == 0 || nl[I_HISTLEN].n_type == 0 ||
- nl[CA_HISTORY].n_type == 0) {
+ if (nl[IA_EXTRALOC].n_type == 0 || nl[I_REXTRALOC].n_type == 0 ||
+ nl[I_TEXTRALOC].n_type == 0 ||
+ nl[I_HISTLEN].n_type == 0 || nl[CA_HISTORY].n_type == 0) {
printf("\
WARNING this kernel doesn't contain all information needed!\n\
WARNING the commands add and change might not work.\n");
diff --git a/usr.sbin/config/ukc.h b/usr.sbin/config/ukc.h
index 7dc534ae27c..df78a5834af 100644
--- a/usr.sbin/config/ukc.h
+++ b/usr.sbin/config/ukc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ukc.h,v 1.13 2015/09/21 14:45:14 guenther Exp $ */
+/* $OpenBSD: ukc.h,v 1.14 2017/09/27 15:14:52 deraadt Exp $ */
/*
* Copyright (c) 1999-2001 Mats O Jansson. All rights reserved.
@@ -37,8 +37,8 @@
#define P_KERNEL_TEXT 7
#define P_VERSION 8
#define IA_EXTRALOC 9
-#define I_NEXTRALOC 10
-#define I_UEXTRALOC 11
+#define I_REXTRALOC 10
+#define I_TEXTRALOC 11
#define I_HISTLEN 12
#define CA_HISTORY 13
#define TZ_TZ 14
@@ -62,8 +62,8 @@ struct nlist nl[] = {
{ "_kernel_text" },
{ "_version" },
{ "_extraloc" },
- { "_nextraloc" },
- { "_uextraloc" },
+ { "_rextraloc" },
+ { "_textraloc" },
{ "_userconf_histlen" },
{ "_userconf_history" },
{ "_tz" },
@@ -86,8 +86,8 @@ struct nlist knl[] = {
{ "_kernel_text" },
{ "_version" },
{ "_extraloc" },
- { "_nextraloc" },
- { "_uextraloc" },
+ { "_rextraloc" },
+ { "_textraloc" },
{ "_userconf_histlen" },
{ "_userconf_history" },
{ "_tz" },
diff --git a/usr.sbin/config/ukcutil.c b/usr.sbin/config/ukcutil.c
index dfb64359c40..fa19c7a2301 100644
--- a/usr.sbin/config/ukcutil.c
+++ b/usr.sbin/config/ukcutil.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ukcutil.c,v 1.22 2016/10/27 14:32:10 tb Exp $ */
+/* $OpenBSD: ukcutil.c,v 1.23 2017/09/27 15:14:52 deraadt Exp $ */
/*
* Copyright (c) 1999-2001 Mats O Jansson. All rights reserved.
@@ -65,10 +65,20 @@ get_locnames(int idx)
}
static long *
-get_extraloc(int idx)
+get_extraloc(int nslots)
{
- return((long *)(adjust((caddr_t)nl[IA_EXTRALOC].n_value) +
- idx * sizeof(long)));
+ long *extralocp, *locp;
+ int *rextralocp, *textralocp;
+
+ extralocp = (long *)adjust((caddr_t)nl[IA_EXTRALOC].n_value);
+ rextralocp = (int *)adjust((caddr_t)nl[I_REXTRALOC].n_value);
+ textralocp = (int *)adjust((caddr_t)nl[I_TEXTRALOC].n_value);
+ if (*rextralocp < nslots)
+ return (NULL);
+
+ locp = &extralocp[*textralocp - *rextralocp];
+ *rextralocp -= nslots;
+ return locp;
}
static char *
@@ -374,7 +384,7 @@ void
change(int devno)
{
int i, share = 0;
- long *j = NULL, *k = NULL, *l;
+ long *j = NULL, *l = NULL;
struct cfdata *cd, *c;
struct pdevinit *pi;
short *ln, *lk;
@@ -417,16 +427,14 @@ change(int devno)
}
lk = ln;
- j = (long *)adjust((caddr_t)nl[I_NEXTRALOC].n_value);
- k = (long *)adjust((caddr_t)nl[I_UEXTRALOC].n_value);
- if ((i + *k) > *j) {
+ j = l = get_extraloc(i);
+ if (l == NULL) {
printf("Not enough space to change device.\n");
return;
}
-
- j = l = get_extraloc(*k);
- bcopy(adjust((caddr_t)cd->cf_loc),
- l, sizeof(long) * i);
+ if (i)
+ bcopy(adjust((caddr_t)cd->cf_loc), l,
+ sizeof(long) * i);
}
while (*ln != -1) {
@@ -438,10 +446,9 @@ change(int devno)
modify("flags", &cd->cf_flags);
if (share) {
- if (bcmp(adjust((caddr_t)cd->cf_loc), j,
- sizeof(long) * i)) {
+ if (bcmp(adjust((caddr_t)cd->cf_loc),
+ j, sizeof(long) * i)) {
cd->cf_loc = (long *)readjust((caddr_t)j);
- *k = *k + i;
}
}
@@ -478,7 +485,7 @@ void
change_history(int devno, char *str)
{
int i, share = 0;
- long *j = NULL, *k = NULL, *l;
+ long *j = NULL, *l = NULL;
struct cfdata *cd, *c;
struct pdevinit *pi;
short *ln, *lk;
@@ -519,16 +526,14 @@ change_history(int devno, char *str)
}
lk = ln;
- j = (long *)adjust((caddr_t)nl[I_NEXTRALOC].n_value);
- k = (long *)adjust((caddr_t)nl[I_UEXTRALOC].n_value);
- if ((i + *k) > *j) {
+ j = l = get_extraloc(i);
+ if (l == NULL) {
printf("Not enough space to change device.\n");
return;
}
-
- j = l = get_extraloc(*k);
- bcopy(adjust((caddr_t)cd->cf_loc),
- l, sizeof(long) * i);
+ if (i)
+ bcopy(adjust((caddr_t)cd->cf_loc), l,
+ sizeof(long) * i);
}
while (*ln != -1) {
@@ -557,7 +562,6 @@ change_history(int devno, char *str)
if (bcmp(adjust((caddr_t)cd->cf_loc),
j, sizeof(long) * i)) {
cd->cf_loc = (long *)readjust((caddr_t)j);
- *k = *k + i;
}
}