summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2015-10-02 09:36:25 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2015-10-02 09:36:25 +0000
commit1896454325611edf28d9977afb183d5d21766ddb (patch)
tree172b7efe94f202b78142ae4aa5c8594ecdb122d6
parent8f51b0208c6772b4f33cb152264ae961a99aa50b (diff)
As the socket path is known, use its size rather that PATH_MAX.
-rw-r--r--lib/libsndio/amsg.h9
-rw-r--r--lib/libsndio/aucat.c6
-rw-r--r--usr.bin/sndiod/sndiod.c10
3 files changed, 16 insertions, 9 deletions
diff --git a/lib/libsndio/amsg.h b/lib/libsndio/amsg.h
index 1a8d6bcabec..d3a5b0cebd5 100644
--- a/lib/libsndio/amsg.h
+++ b/lib/libsndio/amsg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: amsg.h,v 1.8 2015/10/02 09:21:46 ratchov Exp $ */
+/* $OpenBSD: amsg.h,v 1.9 2015/10/02 09:36:24 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -29,6 +29,13 @@
*/
#define SOCKPATH_DIR "/tmp/aucat"
#define SOCKPATH_FILE "aucat"
+#define SOCKPATH_MAX (1 + \
+ sizeof(SOCKPATH_DIR) - 1 + \
+ sizeof(char) + \
+ sizeof(int) * 3 + \
+ sizeof(char) + \
+ sizeof(SOCKPATH_FILE) - 1 + \
+ sizeof(int) * 3)
/*
* server TCP base port number
diff --git a/lib/libsndio/aucat.c b/lib/libsndio/aucat.c
index aa182803a4a..62d1044e44d 100644
--- a/lib/libsndio/aucat.c
+++ b/lib/libsndio/aucat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aucat.c,v 1.65 2015/10/02 09:21:46 ratchov Exp $ */
+/* $OpenBSD: aucat.c,v 1.66 2015/10/02 09:36:24 ratchov Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -337,7 +337,7 @@ aucat_connect_un(struct aucat *hdl, unsigned int unit)
uid = geteuid();
snprintf(ca.sun_path, sizeof(ca.sun_path),
- SOCKPATH_DIR "-%u/%s%u", uid, SOCKPATH_FILE, unit);
+ SOCKPATH_DIR "-%u/" SOCKPATH_FILE "%u", uid, unit);
ca.sun_family = AF_UNIX;
s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (s < 0)
@@ -348,7 +348,7 @@ aucat_connect_un(struct aucat *hdl, unsigned int unit)
DPERROR(ca.sun_path);
/* try shared server */
snprintf(ca.sun_path, sizeof(ca.sun_path),
- SOCKPATH_DIR "/%s%u", SOCKPATH_FILE, unit);
+ SOCKPATH_DIR "/" SOCKPATH_FILE "%u", unit);
while (connect(s, (struct sockaddr *)&ca, len) < 0) {
if (errno == EINTR)
continue;
diff --git a/usr.bin/sndiod/sndiod.c b/usr.bin/sndiod/sndiod.c
index f99a3e2efc6..f26bd6b9a09 100644
--- a/usr.bin/sndiod/sndiod.c
+++ b/usr.bin/sndiod/sndiod.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndiod.c,v 1.9 2015/10/02 09:21:46 ratchov Exp $ */
+/* $OpenBSD: sndiod.c,v 1.10 2015/10/02 09:36:24 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -260,10 +260,10 @@ getbasepath(char *base, size_t size)
uid = geteuid();
if (uid == 0) {
mask = 022;
- snprintf(base, PATH_MAX, SOCKPATH_DIR);
+ snprintf(base, SOCKPATH_MAX, SOCKPATH_DIR);
} else {
mask = 077;
- snprintf(base, PATH_MAX, SOCKPATH_DIR "-%u", uid);
+ snprintf(base, SOCKPATH_MAX, SOCKPATH_DIR "-%u", uid);
}
if (mkdir(base, 0777 & ~mask) < 0) {
if (errno != EEXIST)
@@ -333,7 +333,7 @@ main(int argc, char **argv)
{
int c, background, unit;
int pmin, pmax, rmin, rmax;
- char base[PATH_MAX], path[PATH_MAX];
+ char base[SOCKPATH_MAX], path[SOCKPATH_MAX];
unsigned int mode, dup, mmc, vol;
unsigned int hold, autovol, bufsz, round, rate;
const char *str;
@@ -466,7 +466,7 @@ main(int argc, char **argv)
mode, vol, mmc, dup);
}
getbasepath(base, sizeof(base));
- snprintf(path, PATH_MAX, "%s/%s%u", base, SOCKPATH_FILE, unit);
+ snprintf(path, SOCKPATH_MAX, "%s/%s%u", base, SOCKPATH_FILE, unit);
listen_new_un(path);
if (geteuid() == 0)
privdrop();