summaryrefslogtreecommitdiff
path: root/9mount.c
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2018-09-05 10:47:38 +0200
committerAndrej Shadura <andrewsh@debian.org>2018-09-05 10:47:38 +0200
commit1ae31c787e5fd4567732e0d308463fce432ca3c7 (patch)
treebe238534e36759de427d3d1b2e71c1b64b9296be /9mount.c
parent683eaa36b538f306f7e897e0368c274fc4c8abcc (diff)
parente17168f0a7640e397042f6b47fc056deb1cc9602 (diff)
Update upstream source from tag 'upstream/1.3+hg20170412'
Update to upstream version '1.3+hg20170412' with Debian dir 4b309c6829662e1ac9a3b9855e5bb79aa412980a
Diffstat (limited to '9mount.c')
-rw-r--r--9mount.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/9mount.c b/9mount.c
index 65bccac..80a751d 100644
--- a/9mount.c
+++ b/9mount.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -18,6 +19,10 @@
#define nelem(x) (sizeof(x)/sizeof(*(x)))
+enum {
+ Maxmsize = 8192,
+};
+
struct {char *mnemonic; int mask;} debug_flags[] = {
{"err", 0x001},
{"devel", 0x002},
@@ -92,6 +97,11 @@ parsedial(char *dial, char **network, char **netaddr, int *port)
if ((cp=strtok(NULL, "!"))) {
errx(1, "%s: junk trailing dial string", cp);
}
+ if (strcmp(*network, "unix") == 0) {
+ if (access(*netaddr, R_OK | W_OK)) {
+ err(1, "%s", *netaddr);
+ }
+ }
}
int
@@ -134,6 +144,8 @@ main(int argc, char **argv)
msize = getarg('m', cp, &argv);
*cp-- = '\0';
break;
+ default:
+ errx(1, "unrecognised argument '%c'", *cp);
}
}
} else if (!dial) {
@@ -163,7 +175,7 @@ main(int argc, char **argv)
if (strcmp(dial, "-") == 0) {
proto = "fd";
addr = "nodev";
- append(&opts, "rfdno=0,wrfdno=1", &optlen);
+ append(&opts, "rfdno=0,wfdno=1", &optlen);
} else {
parsedial(dial, &proto, &addr, &port);
}
@@ -182,8 +194,10 @@ main(int argc, char **argv)
}
if (cache) {
- if (strcmp(cache, "loose") != 0) {
- errx(1, "%s: unknown cache mode (expecting loose)", cache);
+ if (strcmp(cache, "loose") != 0
+ && strcmp(cache, "fscache") != 0
+ && strcmp(cache, "mmap") != 0) {
+ errx(1, "%s: unknown cache mode (expecting loose, fscache, or mmap)", cache);
}
snprintf(buf, sizeof(buf), "cache=%s", cache);
append(&opts, buf, &optlen);
@@ -206,10 +220,16 @@ main(int argc, char **argv)
}
if (msize) {
- if (strspn(msize, "0123456789") < strlen(msize)) {
- errx(1, "%s: msize must be an integer", msize);
+ unsigned long nmsize;
+ char *end = NULL;
+ nmsize = strtoul(msize, &end, 10);
+ if (*end || nmsize == 0 || nmsize > INT_MAX) {
+ errx(1, "%s: msize must be a positive integer", msize);
+ }
+ if (pw->pw_uid != 0 && nmsize > Maxmsize) {
+ nmsize = Maxmsize;
}
- snprintf(buf, sizeof(buf), "msize=%s", msize);
+ snprintf(buf, sizeof(buf), "msize=%lu", nmsize);
append(&opts, buf, &optlen);
}
@@ -238,6 +258,9 @@ main(int argc, char **argv)
if (!dev) {
append(&opts, "nodev", &optlen);
}
+ if (pw->pw_uid != 0) {
+ append(&opts, "nosuid", &optlen);
+ }
if (uidgid) {
snprintf(buf, sizeof(buf), "uid=%d,gid=%d", getuid(), getgid());
append(&opts, buf, &optlen); /* < 2.6.24 */
@@ -251,8 +274,12 @@ main(int argc, char **argv)
if (strcmp(proto, "tcp") == 0) {
struct addrinfo *ai;
+ struct addrinfo aihints;
int r;
- if ((r=getaddrinfo(addr, NULL, NULL, &ai))) {
+ memset(&aihints, 0, sizeof(aihints));
+ aihints.ai_family = AF_INET;
+ aihints.ai_socktype = SOCK_STREAM;
+ if ((r=getaddrinfo(addr, NULL, &aihints, &ai))) {
errx(1, "getaddrinfo: %s", gai_strerror(r));
}
if ((r=getnameinfo(ai->ai_addr, ai->ai_addrlen, buf,