Kill client rather than fatalx on bad file handling messages, reported

by Tim Zheng.
This commit is contained in:
nicm
2026-04-23 12:36:15 +00:00
parent ffe80579df
commit 1d9522a7a6
3 changed files with 21 additions and 15 deletions

21
file.c
View File

@@ -807,7 +807,7 @@ file_read_cancel(struct client_files *files, struct imsg *imsg)
} }
/* Handle a write ready message (server). */ /* Handle a write ready message (server). */
void int
file_write_ready(struct client_files *files, struct imsg *imsg) file_write_ready(struct client_files *files, struct imsg *imsg)
{ {
struct msg_write_ready *msg = imsg->data; struct msg_write_ready *msg = imsg->data;
@@ -815,19 +815,20 @@ file_write_ready(struct client_files *files, struct imsg *imsg)
struct client_file find, *cf; struct client_file find, *cf;
if (msglen != sizeof *msg) if (msglen != sizeof *msg)
fatalx("bad MSG_WRITE_READY size"); return (-1);
find.stream = msg->stream; find.stream = msg->stream;
if ((cf = RB_FIND(client_files, files, &find)) == NULL) if ((cf = RB_FIND(client_files, files, &find)) == NULL)
return; return (0);
if (msg->error != 0) { if (msg->error != 0) {
cf->error = msg->error; cf->error = msg->error;
file_fire_done(cf); file_fire_done(cf);
} else } else
file_push(cf); file_push(cf);
return (0);
} }
/* Handle read data message (server). */ /* Handle read data message (server). */
void int
file_read_data(struct client_files *files, struct imsg *imsg) file_read_data(struct client_files *files, struct imsg *imsg)
{ {
struct msg_read_data *msg = imsg->data; struct msg_read_data *msg = imsg->data;
@@ -837,10 +838,10 @@ file_read_data(struct client_files *files, struct imsg *imsg)
size_t bsize = msglen - sizeof *msg; size_t bsize = msglen - sizeof *msg;
if (msglen < sizeof *msg) if (msglen < sizeof *msg)
fatalx("bad MSG_READ_DATA size"); return (-1);
find.stream = msg->stream; find.stream = msg->stream;
if ((cf = RB_FIND(client_files, files, &find)) == NULL) if ((cf = RB_FIND(client_files, files, &find)) == NULL)
return; return (0);
log_debug("file %d read %zu bytes", cf->stream, bsize); log_debug("file %d read %zu bytes", cf->stream, bsize);
if (cf->error == 0 && !cf->closed) { if (cf->error == 0 && !cf->closed) {
@@ -850,10 +851,11 @@ file_read_data(struct client_files *files, struct imsg *imsg)
} else } else
file_fire_read(cf); file_fire_read(cf);
} }
return (0);
} }
/* Handle a read done message (server). */ /* Handle a read done message (server). */
void int
file_read_done(struct client_files *files, struct imsg *imsg) file_read_done(struct client_files *files, struct imsg *imsg)
{ {
struct msg_read_done *msg = imsg->data; struct msg_read_done *msg = imsg->data;
@@ -861,12 +863,13 @@ file_read_done(struct client_files *files, struct imsg *imsg)
struct client_file find, *cf; struct client_file find, *cf;
if (msglen != sizeof *msg) if (msglen != sizeof *msg)
fatalx("bad MSG_READ_DONE size"); return (-1);
find.stream = msg->stream; find.stream = msg->stream;
if ((cf = RB_FIND(client_files, files, &find)) == NULL) if ((cf = RB_FIND(client_files, files, &find)) == NULL)
return; return (0);
log_debug("file %d read done", cf->stream); log_debug("file %d read done", cf->stream);
cf->error = msg->error; cf->error = msg->error;
file_fire_done(cf); file_fire_done(cf);
return (0);
} }

View File

@@ -2239,13 +2239,16 @@ server_client_dispatch(struct imsg *imsg, void *arg)
goto bad; goto bad;
break; break;
case MSG_WRITE_READY: case MSG_WRITE_READY:
file_write_ready(&c->files, imsg); if (file_write_ready(&c->files, imsg) != 0)
goto bad;
break; break;
case MSG_READ: case MSG_READ:
file_read_data(&c->files, imsg); if (file_read_data(&c->files, imsg) != 0)
goto bad;
break; break;
case MSG_READ_DONE: case MSG_READ_DONE:
file_read_done(&c->files, imsg); if (file_read_done(&c->files, imsg) != 0)
goto bad;
break; break;
} }

6
tmux.h
View File

@@ -2949,9 +2949,9 @@ void file_write_data(struct client_files *, struct imsg *);
void file_write_close(struct client_files *, struct imsg *); void file_write_close(struct client_files *, struct imsg *);
void file_read_open(struct client_files *, struct tmuxpeer *, struct imsg *, void file_read_open(struct client_files *, struct tmuxpeer *, struct imsg *,
int, int, client_file_cb, void *); int, int, client_file_cb, void *);
void file_write_ready(struct client_files *, struct imsg *); int file_write_ready(struct client_files *, struct imsg *);
void file_read_data(struct client_files *, struct imsg *); int file_read_data(struct client_files *, struct imsg *);
void file_read_done(struct client_files *, struct imsg *); int file_read_done(struct client_files *, struct imsg *);
void file_read_cancel(struct client_files *, struct imsg *); void file_read_cancel(struct client_files *, struct imsg *);
/* server.c */ /* server.c */