Description: No unconditional use of PATH_MAX in non-linux-specific code . Needed for portability to systems which do not in fact have a maximum path length and therefore do not define PATH_MAX, specifically debian's hurd-i386 port. Index: git/libsndio/aucat.c =================================================================== --- git.orig/libsndio/aucat.c +++ git/libsndio/aucat.c @@ -245,9 +245,12 @@ static int aucat_mkcookie(unsigned char *cookie) { struct stat sb; - char buf[PATH_MAX], tmp[PATH_MAX], *path; + char *buf, *tmp, *path; + ssize_t path_len; ssize_t len; - int fd; + int fd, ret; + + buf = tmp = path = NULL; /* * try to load the cookie @@ -257,7 +260,8 @@ aucat_mkcookie(unsigned char *cookie) path = issetugid() ? NULL : getenv("HOME"); if (path == NULL) goto bad_gen; - snprintf(buf, PATH_MAX, "%s/.aucat_cookie", path); + buf = malloc(path_len = strlen(path) + 14 + 1); + snprintf(buf, path_len, "%s/.aucat_cookie", path); path = buf; } fd = open(path, O_RDONLY); @@ -284,7 +288,8 @@ aucat_mkcookie(unsigned char *cookie) goto bad_close; } close(fd); - return 1; + ret = 1; + goto free; bad_close: close(fd); bad_gen: @@ -294,37 +299,52 @@ bad_gen: #ifdef HAVE_ARC4RANDOM arc4random_buf(cookie, AMSG_COOKIELEN); #else - if (!random_bytes(cookie, AMSG_COOKIELEN)) - return 0; + if (!random_bytes(cookie, AMSG_COOKIELEN)) { + ret = 0; + goto free; + } #endif /* * try to save the cookie */ - if (path == NULL) - return 1; - if (strlcpy(tmp, path, PATH_MAX) >= PATH_MAX || - strlcat(tmp, ".XXXXXXXX", PATH_MAX) >= PATH_MAX) { + if (path == NULL) { + ret = 1; + goto free; + } + + tmp = malloc (path_len = strlen(path) + 9 + 1); +#ifdef PATH_MAX + if (path_len > PATH_MAX) { DPRINTF("%s: too long\n", path); - return 1; + ret = 1; + goto free; } +#endif + snprintf (tmp, path_len, "%s.XXXXXXXX", path); fd = mkstemp(tmp); if (fd < 0) { DPERROR(tmp); - return 1; + ret = 1; + goto free; } if (write(fd, cookie, AMSG_COOKIELEN) < 0) { DPERROR(tmp); unlink(tmp); close(fd); - return 1; + ret = 1; + goto free; } close(fd); if (rename(tmp, path) < 0) { DPERROR(tmp); unlink(tmp); + ret = 1; } - return 1; +free: + free(buf); + free(tmp); + return ret; } static int Index: git/libsndio/mio_rmidi.c =================================================================== --- git.orig/libsndio/mio_rmidi.c +++ git/libsndio/mio_rmidi.c @@ -56,7 +56,11 @@ _mio_rmidi_open(const char *str, unsigne { int fd, flags; struct mio_rmidi_hdl *hdl; - char path[PATH_MAX]; + char *path; + int path_len; + + hdl = NULL; + path = NULL; switch (*str) { case '/': @@ -71,7 +75,8 @@ _mio_rmidi_open(const char *str, unsigne return NULL; _mio_create(&hdl->mio, &mio_rmidi_ops, mode, nbio); - snprintf(path, sizeof(path), "/dev/rmidi%s", str); + path = malloc(path_len = strlen(str) + 10 + 1); + snprintf(path, path_len, "/dev/rmidi%s", str); if (mode == (MIO_OUT | MIO_IN)) flags = O_RDWR; else @@ -86,6 +91,7 @@ _mio_rmidi_open(const char *str, unsigne return (struct mio_hdl *)hdl; bad_free: free(hdl); + free(path); return NULL; } Index: git/sndiod/sndiod.c =================================================================== --- git.orig/sndiod/sndiod.c +++ git/sndiod/sndiod.c @@ -92,7 +92,7 @@ int opt_mmc(void); int opt_onoff(void); int getword(char *, char **); unsigned int opt_mode(void); -void getbasepath(char *, size_t); +char *getbasepath(size_t *); void setsig(void); void unsetsig(void); void privdrop(void); @@ -251,20 +251,25 @@ unsetsig(void) err(1, "unsetsig(int): sigaction failed\n"); } -void -getbasepath(char *base, size_t size) +char* +getbasepath(size_t *base_len) { uid_t uid; struct stat sb; mode_t mask; + char *base; uid = geteuid(); if (uid == 0) { mask = 022; - snprintf(base, PATH_MAX, "/tmp/aucat"); + base = malloc(*base_len = 10 + 1); + snprintf(base, *base_len, "/tmp/aucat"); } else { + char uid_str[128]; mask = 077; - snprintf(base, PATH_MAX, "/tmp/aucat-%u", uid); + snprintf(uid_str, sizeof(uid_str), "%u", uid); + base = malloc(*base_len = 11 + strlen(uid_str) + 1); + snprintf(base, *base_len, "/tmp/aucat-%u", uid); } if (mkdir(base, 0777 & ~mask) < 0) { if (errno != EEXIST) @@ -274,6 +279,7 @@ getbasepath(char *base, size_t size) err(1, "stat(\"%s\")", base); if (sb.st_uid != uid || (sb.st_mode & mask) != 0) errx(1, "%s has wrong permissions", base); + return base; } void @@ -334,7 +340,8 @@ main(int argc, char **argv) { int c, background, unit; int pmin, pmax, rmin, rmax; - char base[PATH_MAX], path[PATH_MAX]; + char *base, *path; + size_t base_len, path_len; unsigned int mode, dup, mmc, vol; unsigned int hold, autovol, bufsz, round, rate; const char *str; @@ -466,23 +473,31 @@ main(int argc, char **argv) mkopt("default", d, pmin, pmax, rmin, rmax, mode, vol, mmc, dup); } - getbasepath(base, sizeof(base)); - snprintf(path, PATH_MAX, "%s/%s%u", base, AUCAT_PATH, unit); + base = getbasepath(&base_len); + path = malloc(path_len = base_len + strlen(AUCAT_PATH) + 2 + 1); + snprintf(path, path_len, "%s/%s%u", base, AUCAT_PATH, unit); listen_new_un(path); + free(path); if (geteuid() == 0) privdrop(); midi_init(); for (p = port_list; p != NULL; p = p->next) { - if (!port_init(p)) + if (!port_init(p)) { + free(base); return 1; + } } for (d = dev_list; d != NULL; d = d->next) { - if (!dev_init(d)) + if (!dev_init(d)) { + free(base); return 1; + } } for (l = listen_list; l != NULL; l = l->next) { - if (!listen_init(l)) + if (!listen_init(l)) { + free(base); return 1; + } } if (background) { log_flush();