From 796e8897bd8b94851d20a9275bdfd45d6eefd26b Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Tue, 25 Jun 2024 07:55:09 +0200 Subject: [PATCH] Add more error handling --- src/mod/share.mod/share.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mod/share.mod/share.c b/src/mod/share.mod/share.c index b030586c4..c4dcb0253 100644 --- a/src/mod/share.mod/share.c +++ b/src/mod/share.mod/share.c @@ -26,6 +26,7 @@ #include #include "src/mod/module.h" +#include #include #include @@ -1228,11 +1229,11 @@ static void share_userfileq(int idx, char *par) /* New user file share mechanism via multiplex over already existing bot link * ur */ -#include static void share_ufsend2(int idx, char *par) { int len; unsigned char *buf; + ssize_t i; len = strlen(par); debug2("share: share_ufsend2(): start: par = >%s< len = %i", par, len); @@ -1248,7 +1249,13 @@ static void share_ufsend2(int idx, char *par) putlog(LOG_BOTS, "*", "share: share_ufsend2(): error mkstemp(): %s", strerror(errno)); return; } - write(fd, buf, len); /* TODO: error handling */ + if ((i = write(fd, buf, len)) != len) { + if (i < 0) + putlog(LOG_MISC, "*", "Share error: sare_ufsend2(): write(): %s", strerror(errno)); + else + putlog(LOG_MISC, "*", "share error: sare_ufsend2(): write(): Wrote %ld bytes instead of %i bytes.", (long) i, len); + return; + } close(fd); dcc[idx].u.xfer->filename = template; /* The new method has got no extra dcc[] for the file transfer,