|
#1
|
|||
|
|||
Накопившиеся патчи
Nil A написал(а) к All в Mar 24 07:02:22 по местному времени:
Нello, All! А есть какай-то ru.binkd.devel или binkd.devel эха? Почему одобренный PR от Виталия, с фиксом дат в отладочный вывод, так и висит не смёрженным больше года https://github.com/pgul/binkd/pull/38 ? Я за какое-то время накопил своих фиксов и предлагаю их сюда одним коммитом. -Begin file 0001-Squashed-commits-with-various-fixes.patch- From 5480c96b253b52d89800fcabaf32f6451e389ce4 Mon Sep 17 00:00:00 2001 From: Nil Alexandrov <nil.alexandrov@gmail.com> Date: Thu, 7 Mar 2024 06:57:59 +0300 Subject: [PATCН] Squashed commits with various fixes. * Fixed a few memory leaks. * Fixed possible string overflows with sprint. * Fixed possible unterminated string after strncpy. * Fixed log messages, missed arguments, mismatches with type specifiers. * Fixed const correctness warnings. -+- client.c | 3 ++- ftnq.c | 6 +++--- ftnq.h | 2 +- https.c | 3 ++- inbound.c | 1 + iptools.c | 16 ++++++++++------ ntlm/helpers.c | 1 + perlhooks.c | 7 +++++++ protocol.c | 21 ++++++++++++--------- readcfg.c | 13 ++++++++----- tools.c | 10 +++++----- tools.h | 6 ++++++ 12 files changed, 58 insertions(+), 31 deletions(-) diff --git a/client.c b/client.c index 81dfefe..bc61379 100644 --- a/client.c +++ b/client.c @@ -370,6 +370,7 @@ static int call0 (FTNNODE node, BINKDCONFIG config) { char sp, sport; strncpy(host, proxy[0] ? proxy : socks, sizeof(host)); + host[sizeof(host) - 1] = '\0'; if ((sp=strchr(host, ':')) != NULL) { *sp++ = '\0'; @@ -428,7 +429,7 @@ static int call0 (FTNNODE node, BINKDCONFIG config) } if (!binkd_exit) { - Log (1, "connection to %s failed"); + Log (1, "connection to %s failed", host); / badtry (&node->fa, "exec error", BADCALL, config); / } sockfd = INVALID_SOCKET; diff --git a/ftnq.c b/ftnq.c index dcdaef8..d211051 100644 --- a/ftnq.c +++ b/ftnq.c @@ -332,7 +332,7 @@ FTNQ qscan_boxes (FTNQ *q, FTN_ADDR *fa, int n, int to, BINKDCONFIG config) strnzcpy (buf, config->bfilebox, sizeof (buf)); strnzcat (buf, PATН_SEPARATOR, sizeof (buf)); snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), - "%s.%u.%u.%u.%u.", + "%s.%d.%d.%d.%d.", fa[i].domain, fa[i].z, fa[i].net, @@ -1050,7 +1050,7 @@ void holdnode (FTN_ADDR fa, time_t hold_until, BINKDCONFIG config) } } -void writetry (FTN_ADDR fa, unsigned *nok, unsigned *nbad, char *comment, BINKDCONFIG config) +void writetry (FTN_ADDR fa, unsigned *nok, unsigned *nbad, const char *comment, BINKDCONFIG config) { char buf[MAXPATНLEN + 1]; @@ -1117,7 +1117,7 @@ void badtry (FTN_ADDR fa, const char *error, const int where, BINKDCONFIG co nok = nbad = 0; holdnode (fa, safetime() + config->hold, config); } - write_try (fa, &nok, &nbad, (char *) error, config); + write_try (fa, &nok, &nbad, error, config); } void goodtry (FTN_ADDR fa, char *comment, BINKDCONFIG config) diff --git a/ftnq.h b/ftnq.h index fe55056..c101ac8 100644 --- a/ftnq.h +++ b/ftnq.h @@ -112,7 +112,7 @@ enum badtry_type { BAD_NA, BAD_CALL, BAD_MERR, BAD_MBSY, BAD_IO, BADTIMEOUT, void badtry (FTN_ADDR fa, const char *error, const int where, BINKDCONFIG config); void goodtry (FTN_ADDR fa, char *comment, BINKDCONFIG config); void readtry (FTN_ADDR fa, unsigned *nok, unsigned *nbad, BINKDCONFIG config); -void writetry (FTN_ADDR fa, unsigned *nok, unsigned *nbad, char *comment, BINKDCONFIG config); +void writetry (FTN_ADDR fa, unsigned *nok, unsigned *nbad, const char *comment, BINKDCONFIG config); void removetry (FTN_ADDR fa, BINKDCONFIG config); #endif diff --git a/https.c b/https.c index 05f98b0..777467e 100644 --- a/https.c +++ b/https.c @@ -369,9 +369,10 @@ int hconnect(int so, const char host, const char *port, BINKDCONFIG config, return 1; } if ((n=recv(so, buf+i, 1, 0))<1) { - if (n<0) + if (n<0) { Log(2, "socks error: %s", TCPERR()); Log(2, "connection closed by socks server..."); + } if (sauth) free(sauth); freeaddrinfo(aiНead); SetTCPError(PR_ERROR); diff --git a/inbound.c b/inbound.c index 3e65613..c2cc9ac 100644 --- a/inbound.c +++ b/inbound.c @@ -196,6 +196,7 @@ static int findtmp_name (char s, TFILE *file, STATE *state, BINKDCONFIG conf Log (2, "Skip partial file %s: aka %s busy", w[0], w[3]); for (i = 0; i < 4; ++i) xfree (w[i]); + closedir (dp); return 0; } else diff --git a/iptools.c b/iptools.c index be1def9..4154b9e 100644 --- a/iptools.c +++ b/iptools.c @@ -100,12 +100,16 @@ int sockaddrcmpaddr(const struct sockaddr a, const struct sockaddr b) return a->safamily - b->safamily; if (a->safamily == AFINET) - return (((struct sockaddrin)a)->sin_addr.s_addr - ((struct sockaddr_in)b)->sin_addr.saddr); + / Compiler can produce a warning here, cast from sockaddr* to sockaddr_in + * increases required alignment. This can be ignored because objects a and + * b are pointing to sockaddrin or sockaddrin6, determined by checking + sa_family, so the operation is safe. / + return (((const struct sockaddrin)a)->sin_addr.s_addr - ((const struct sockaddr_in)b)->sin_addr.saddr); #ifdef AF_INET6 else if (a->safamily == AFINET6) - return memcmp((char ) &(((struct sockaddrin6)a)->sin6addr), - (char ) &(((struct sockaddrin6)b)->sin6addr), - sizeof(((struct sockaddrin6*)a)->sin6addr)); + return memcmp(&(((const struct sockaddrin6*)a)->sin6addr), + &(((const struct sockaddrin6*)b)->sin6addr), + sizeof((struct sockaddrin6*)0)->sin6addr); #endif else { @@ -120,10 +124,10 @@ int sockaddrcmpport(const struct sockaddr a, const struct sockaddr b) return a->safamily - b->safamily; if (a->safamily == AFINET) - return (((struct sockaddrin)a)->sin_port - ((struct sockaddr_in)b)->sinport); + return (((const struct sockaddrin)a)->sin_port - ((const struct sockaddr_in)b)->sinport); #ifdef AF_INET6 else if (a->safamily == AFINET6) - return (((struct sockaddrin6)a)->sin6_port - ((struct sockaddr_in6)b)->sin6port); + return (((const struct sockaddrin6)a)->sin6_port - ((const struct sockaddr_in6)b)->sin6port); #endif else { diff --git a/ntlm/helpers.c b/ntlm/helpers.c index 358f0c7..590254b 100644 --- a/ntlm/helpers.c +++ b/ntlm/helpers.c @@ -328,5 +328,6 @@ int getNTLM2(char udata, char *req, char result, sizet ressize) m.msg_len = mkls(j); if (res_size < j*4/3+4) return -1; enbase64((char*)&m, j, result); + free(user); return 0; } diff --git a/perlhooks.c b/perlhooks.c index 4265df9..e256626 100644 --- a/perlhooks.c +++ b/perlhooks.c @@ -1811,6 +1811,13 @@ int perlon_call(FTN_NODE node, BINKDCONFIG *cfg, char *hosts } } releaseperlsem(); + // release memory + while (q) + { + FTNQ *next = q->next; + free(q); + q = next; + } Log(LLDBG, "perl_oncall() end"); return rc; } diff --git a/protocol.c b/protocol.c index 677cb44..5974445 100644 --- a/protocol.c +++ b/protocol.c @@ -285,6 +285,9 @@ void msgsend2 (STATE state, tmsg m, char *s1, char s2) /* * Sends a message using format string */ +#ifdef _GNUC_ +_attribute_ ((format (printf, 3, 4))) +#endif static void msgsendf (STATE state, tmsg m, char s,...) { char msgtext[max (MAXPATНLEN, MAXNETNAME) + 80]; @@ -1499,7 +1502,7 @@ static int ADR (STATE state, char *s, int sz, BINKD_CONFIG config) else state->bwsend.rel = -pn->bwsend; } if (state->bwsend.abs || state->bwsend.rel) - Log (7, "Session send rate limit is %s cps or %d%%", + Log (7, "Session send rate limit is %s cps or %lu%%", describerate(state->bw_send.abs), state->bwsend.rel); if (bwrecv_unlim) state->bw_recv.abs = state->bwrecv.rel = 0; @@ -1509,7 +1512,7 @@ static int ADR (STATE state, char *s, int sz, BINKD_CONFIG config) else state->bwrecv.rel = -pn->bwrecv; } if (state->bwrecv.abs || state->bwrecv.rel) - Log (7, "Session recv rate limit is %s cps or %d%%", + Log (7, "Session recv rate limit is %s cps or %lu%%", describerate(state->bw_recv.abs), state->bwrecv.rel); #endif @@ -1624,7 +1627,7 @@ static int PWD (STATE state, char *pwd, int sz, BINKD_CONFIG config) return 1; } if (state->state != P_NULL) - { Log (2, "Double M_PWD from remote! Ignored.", pwd); + { Log (2, "Double M_PWD from remote! Ignored: `%s'.", pwd); msgsend2 (state, M_NUL, "MSG Warning: double of password is received (MPWD more one)!", 0); return 0; } @@ -1809,7 +1812,7 @@ static void setuprate_limit (STATE state, BINKDCONFIG *config, BW bw, perlsetuprlimit(state, bw, fname); #endif if (bw->rlim) - Log (3, "rate limit for %s is %d cps", fname, bw->rlim); + Log (3, "rate limit for %s is %lu cps", fname, bw->rlim); else Log (5, "rate for %s is unlimited", fname); bw->utime.tvsec = bw->utime.tvusec = 0; @@ -1931,7 +1934,7 @@ static int startfile_recv (STATE state, char *args, int sz, BINKDCONFIG conf errno=0; state->in.time = safe_atol (argv[2], &errmesg); if (errmesg) { - Log ( 1, "File time parsing error: %s! (M_FILE \"%s %s %s %s\")", errmesg, argv[0], argv[1], argv[0], argv[2], argv[3] ); + Log ( 1, "File time parsing error: %s! (M_FILE \"%s %s %s %s %s\")", errmesg, argv[0], argv[1], argv[0], argv[2], argv[3] ); } } offset = (boff_t) strtoumax (argv[3], NULL, 10); @@ -2205,7 +2208,7 @@ static int GET (STATE state, char *args, int sz, BINKD_CONFIG config) fsize = (boff_t)strtoumax (argv[1], NULL, 10); ftime = safe_atol (argv[2], &errmesg); if(errmesg){ - Log ( 1, "File time parsing error: %s! (M_GET \"%s %s %s %s\")", errmesg, argv[0], argv[1], argv[0], argv[2], argv[3] ); + Log ( 1, "File time parsing error: %s! (M_GET \"%s %s %s %s %s\")", errmesg, argv[0], argv[1], argv[0], argv[2], argv[3] ); } } / Check if the file was already sent / @@ -2344,7 +2347,7 @@ static int SKIP (STATE state, char *args, int sz, BINKD_CONFIG config) ftime = safe_atol (argv[2], &errmesg); if (errmesg) { - Log ( 1, "File time parsing error: %s! (M_SKIP \"%s %s %s\")", errmesg, argv[0], argv[1], argv[0], argv[2] ); + Log ( 1, "File time parsing error: %s! (M_SKIP \"%s %s %s %s\")", errmesg, argv[0], argv[1], argv[0], argv[2] ); } } for (n = 0; n < state->nsentfls; ++n) @@ -2413,7 +2416,7 @@ static int GOT (STATE state, char *args, int sz, BINKD_CONFIG config) ftime = safe_atol (argv[2], &errmesg); if (errmesg) { - Log ( 1, "File time parsing error: %s! (M_GOT \"%s %s %s\")", errmesg, argv[0], argv[1], argv[0], argv[2] ); + Log ( 1, "File time parsing error: %s! (M_GOT \"%s %s %s %s\")", errmesg, argv[0], argv[1], argv[0], argv[2] ); } if (!tfile_cmp (&state->out, argv[0], fsize, ftime)) { @@ -3354,7 +3357,7 @@ void protocol (SOCKET socketin, SOCKET socket_out, FTN_NODE to, FTNADDR fa, state.io_error = 1; if (!binkd_exit) { - Log (1, "select: %s (args: %i %i)", saveerr, socket_in, tv.tvsec); + Log (1, "select: %s (args: %i %li)", saveerr, socket_in, (long)tv.tvsec); if (to) badtry (&to->fa, save_err, BADIO, config); } diff --git a/readcfg.c b/readcfg.c index f1077b0..b301392 100644 --- a/readcfg.c +++ b/readcfg.c @@ -528,6 +528,9 @@ static int check_outbox(char *obox) return 0; } +#ifdef _GNUC_ +_attribute_ ((format (printf, 1, 2))) +#endif static int ConfigError(char *format, ...) { va_list args; @@ -729,7 +732,7 @@ static int readcfg0 (char *path) else success = ConfigError("%s: unknown keyword", words[0]); } - while (--wordcount > 0) + while (--wordcount >= 0) free (words[wordcount]); } @@ -2038,10 +2041,10 @@ char *describe_rate(long rate) static char buf[12]; int c; if (rate == 0) return "-"; - else if (rate < 0) c = sprintf(buf, "%ld%%", -rate); - else if (rate >= (1 << 20) && (rate & ((1 << 20) - 1)) == 0) c = sprintf(buf, "%ldM", rate >> 20); - else if (rate >= (1 << 10) && (rate & ((1 << 10) - 1)) == 0) c = sprintf(buf, "%ldk", rate >> 10); - else c = sprintf(buf, "%ld", rate); + else if (rate < 0) c = snprintf(buf, sizeof(buf), "%ld%%", -rate); + else if (rate >= (1 << 20) && (rate & ((1 << 20) - 1)) == 0) c = snprintf(buf, sizeof(buf), "%ldM", rate >> 20); + else if (rate >= (1 << 10) && (rate & ((1 << 10) - 1)) == 0) c = snprintf(buf, sizeof(buf), "%ldk", rate >> 10); + else c = snprintf(buf, sizeof(buf), "%ld", rate); buf[c] = 0; return buf; } diff --git a/tools.c b/tools.c index efdc304..69928b2 100644 --- a/tools.c +++ b/tools.c @@ -162,12 +162,12 @@ int createsemfile (char *name, int errloglevel) { Log (errloglevel, "Can't create %s: %s", name, strerror(errno)); return 0; } - snprintf (buf, sizeof (buf), "%u\n", (int) getpid ()); + snprintf (buf, sizeof (buf), "%ld\n", (long) getpid ()); if ((i = write(h, buf, strlen(buf))) != (int)strlen(buf)) { if (i == -1) Log (2, "Can't write to %s (handle %d): %s", name, h, strerror(errno)); else - Log (2, "Can't write %d bytes to %s, wrote only %d", strlen(buf), name, i); + Log (2, "Can't write %lu bytes to %s, wrote only %d", strlen(buf), name, i); } close (h); Log (5, "created %s", name); @@ -409,8 +409,8 @@ int omemicmp (const void s1, const void s2, sizet n) int i; for (i = 0; i < (int) n; ++i) - if (tolower (((char [i]) s1)) != tolower (((char ) s2)[i])) - return (tolower (((char [i]) s1)) - tolower (((char ) s2)[i])); + if (tolower (((const char [i]) s1)) != tolower (((const char ) s2)[i])) + return (tolower (((const char [i]) s1)) - tolower (((const char ) s2)[i])); return 0; } @@ -555,7 +555,7 @@ char parse_args (int argc, char *argv[], char *src, char ID) } if (i < argc) { - Log (1, "%s: cannot parse args", ID, src); + Log (1, "%s: cannot parse args %s", ID, src); return NULL; } else diff --git a/tools.h b/tools.h index c5b6840..acf28a5 100644 --- a/tools.h +++ b/tools.h @@ -34,7 +34,13 @@ #define max(x,y) ((x) > (y) ? (x) : (y)) #endif +#ifdef _GNUC_ +_attribute_ ((format (printf, 2, 0))) +#endif void vLog (int lev, char *s, va_list ap); +#ifdef _GNUC_ +_attribute_ ((format (printf, 2, 3))) +#endif void Log (int lev, char *s, ...); void InitLog(int loglevel, int conlog, char logpath, void first); -- 1.9.1 -End file 0001-Squashed-commits-with-various-fixes.patch- Best Regards, Nil --- GoldED+/LNX 1.1.5 |