summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2021-01-29 11:25:05 +0000
committerratchov <ratchov@openbsd.org>2021-01-29 11:25:05 +0000
commit869641a98e63d5087aa35c83f1a44c857395e351 (patch)
tree2f820fa62edeaf23784e16aad18460f476e2afb4
parentMove the options list out of the device structure (diff)
downloadwireguard-openbsd-869641a98e63d5087aa35c83f1a44c857395e351.tar.xz
wireguard-openbsd-869641a98e63d5087aa35c83f1a44c857395e351.zip
Order opt_list in opt_new() call order, limit items to OPT_NMAX
No behavior change, except for improved debug printfs.
-rw-r--r--usr.bin/sndiod/opt.c33
-rw-r--r--usr.bin/sndiod/opt.h5
2 files changed, 25 insertions, 13 deletions
diff --git a/usr.bin/sndiod/opt.c b/usr.bin/sndiod/opt.c
index aff4bb2f573..9e7a221f3d5 100644
--- a/usr.bin/sndiod/opt.c
+++ b/usr.bin/sndiod/opt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: opt.c,v 1.5 2021/01/29 11:21:00 ratchov Exp $ */
+/* $OpenBSD: opt.c,v 1.6 2021/01/29 11:25:05 ratchov Exp $ */
/*
* Copyright (c) 2008-2011 Alexandre Ratchov <alex@caoua.org>
*
@@ -30,17 +30,10 @@ opt_new(struct dev *d, char *name,
int pmin, int pmax, int rmin, int rmax,
int maxweight, int mmc, int dup, unsigned int mode)
{
- struct opt *o;
- unsigned int len;
+ struct opt *o, **po;
+ unsigned int len, num;
char c;
- if (opt_byname(d, name)) {
- dev_log(d);
- log_puts(".");
- log_puts(name);
- log_puts(": already defined\n");
- return NULL;
- }
for (len = 0; name[len] != '\0'; len++) {
if (len == OPT_NAMEMAX) {
log_puts(name);
@@ -55,7 +48,23 @@ opt_new(struct dev *d, char *name,
return NULL;
}
}
+ num = 0;
+ for (po = &opt_list; *po != NULL; po = &(*po)->next)
+ num++;
+ if (num >= OPT_NMAX) {
+ log_puts(name);
+ log_puts(": too many opts\n");
+ return NULL;
+ }
+ if (opt_byname(d, name)) {
+ dev_log(d);
+ log_puts(".");
+ log_puts(name);
+ log_puts(": already defined\n");
+ return NULL;
+ }
o = xmalloc(sizeof(struct opt));
+ o->num = num;
o->dev = d;
if (mode & MODE_PLAY) {
o->pmin = pmin;
@@ -70,8 +79,8 @@ opt_new(struct dev *d, char *name,
o->dup = dup;
o->mode = mode;
memcpy(o->name, name, len + 1);
- o->next = opt_list;
- opt_list = o;
+ o->next = *po;
+ *po = o;
if (log_level >= 2) {
dev_log(d);
log_puts(".");
diff --git a/usr.bin/sndiod/opt.h b/usr.bin/sndiod/opt.h
index 9c12639aec5..b9737f8ea34 100644
--- a/usr.bin/sndiod/opt.h
+++ b/usr.bin/sndiod/opt.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: opt.h,v 1.3 2021/01/29 11:21:00 ratchov Exp $ */
+/* $OpenBSD: opt.h,v 1.4 2021/01/29 11:25:05 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -17,11 +17,14 @@
#ifndef OPT_H
#define OPT_H
+#define OPT_NMAX 16
+
struct dev;
struct opt {
struct opt *next;
struct dev *dev;
+ int num;
#define OPT_NAMEMAX 11
char name[OPT_NAMEMAX + 1];
int maxweight; /* max dynamic range for clients */