From 57331e2092ec8d7cd5ebb4b8b6ec2bdf2d2b5661 Mon Sep 17 00:00:00 2001 From: human Date: Mon, 4 Jan 2021 11:40:22 +0200 Subject: macfuse fix attempt --- fs/tabfs.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'fs') diff --git a/fs/tabfs.c b/fs/tabfs.c index d00e96c..5c27faf 100644 --- a/fs/tabfs.c +++ b/fs/tabfs.c @@ -57,7 +57,7 @@ static void write_or_die(int fd, void *buf, size_t sz) { } // documented somewhere in https://developer.chrome.com/docs/apps/nativeMessaging/ -#define MAX_MESSAGE_SIZE (1024*1024) +#define MAX_MESSAGE_SIZE (size_t)(1024*1024) static int do_exchange(unsigned int id, char **datap, size_t *sizep, @@ -65,16 +65,17 @@ static int do_exchange(unsigned int id, *datap = NULL; *sizep = 0; - char jsonbuf[MAX_MESSAGE_SIZE]; - struct json_out out = JSON_OUT_BUF(jsonbuf, sizeof(jsonbuf)); + char *jsonbuf = malloc(MAX_MESSAGE_SIZE); + struct json_out out = JSON_OUT_BUF(jsonbuf, MAX_MESSAGE_SIZE); va_list args; va_start(args, fmt); size_t request_size = (size_t)json_vprintf(&out, fmt, args); va_end(args); - if (request_size > sizeof(jsonbuf)) { + if (request_size > MAX_MESSAGE_SIZE) { eprintln("warning: request too big to send (%zu > %zu)", - request_size, sizeof(jsonbuf)); + request_size, MAX_MESSAGE_SIZE); + free(jsonbuf); return -EMSGSIZE; } @@ -86,6 +87,7 @@ static int do_exchange(unsigned int id, }; if (-1 == pipe(mydata.msgpipe)) { perror("exchange: pipe"); + free(jsonbuf); return -EIO; } @@ -96,6 +98,8 @@ static int do_exchange(unsigned int id, write_or_die(STDOUT_FILENO, &size_4bytes, sizeof(size_4bytes)); write_or_die(STDOUT_FILENO, jsonbuf, request_size); + free(jsonbuf); jsonbuf = NULL; + waiters = realloc(waiters, (numwaiters+1)*sizeof(*waiters)); waiters[numwaiters] = &mydata; numwaiters += 1; @@ -175,7 +179,7 @@ static int count_fmt_args(const char *s) { #define exchange_json(datap, sizep, keys_fmt, ...) \ do { \ - unsigned int id = pthread_self(); \ + unsigned int id = (uintptr_t)pthread_self(); \ int req_rv = do_exchange(id, datap, sizep, \ "{id: %u, " keys_fmt "}", \ id, ##__VA_ARGS__); \ @@ -464,7 +468,9 @@ int main(int argc, char **argv) { char *fuse_argv[] = { argv[0], "-f", +#if !defined(__APPLE__) "-oauto_unmount", +#endif "-odirect_io", "mnt", NULL, -- cgit v1.2.3