forum.wfido.ru

forum.wfido.ru (http://forum.wfido.ru/index.php)
-   RU.BINKD (http://forum.wfido.ru/forumdisplay.php?f=60)
-   -   Накопившиеся патчи (http://forum.wfido.ru/showthread.php?t=129120)

Nil A 07.03.2024 08:21

Накопившиеся патчи
 
Nil A написал(а) к All в Mar 24 07:02:22 по местному времени:

Нello, All!

А есть какай-то ru.binkd.devel или binkd.devel эха?

Почему одобренный PR от Виталия, с фиксом дат в отладочный вывод, так и висит не смёрженным больше года [url]https://github.com/pgul/binkd/pull/38[/url] ?

Я за какое-то время накопил своих фиксов и предлагаю их сюда одним коммитом.

-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 (FTN[b]NODE [i]node, BINKD[/b]CONFIG [/i]config)
{
char [i]sp, [/i]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 (FTN[b]NODE [i]node, BINKD[/b]CONFIG [/i]config)
}
if (!binkd_exit)
{
- Log (1, "connection to %s failed");
+ Log (1, "connection to %s failed", host);
/[i] bad[b]try (&node->fa, "exec error", BAD[/b]CALL, config); [/i]/
}
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 [i]q[b]scan_boxes (FTNQ *q, FTN_ADDR *fa, int n, int to, BINKD[/b]CONFIG [/i]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 hold[b]node (FTN_ADDR [i]fa, time_t hold_until, BINKD[/b]CONFIG [/i]config)
}
}

-void write[b]try (FTN_ADDR [i]fa, unsigned *nok, unsigned *nbad, char *comment, BINKD[/b]CONFIG [/i]config)
+void write[b]try (FTN_ADDR [i]fa, unsigned *nok, unsigned *nbad, const char *comment, BINKD[/b]CONFIG [/i]config)
{
char buf[MAXPATНLEN + 1];

@@ -1117,7 +1117,7 @@ void bad[b]try (FTN_ADDR [i]fa, const char *error, const int where, BINKD[/b]CONFIG [/i]co
nok = nbad = 0;
hold[b]node (fa, safe[/b]time() + config->hold, config);
}
- write_try (fa, &nok, &nbad, (char *) error, config);
+ write_try (fa, &nok, &nbad, error, config);
}

void good[b]try (FTN_ADDR [i]fa, char *comment, BINKD[/b]CONFIG [/i]config)
diff --git a/ftnq.h b/ftnq.h
index fe55056..c101ac8 100644
--- a/ftnq.h
+++ b/ftnq.h
@@ -112,7 +112,7 @@ enum bad[b]try_type { BAD_NA, BAD_CALL, BAD_MERR, BAD_MBSY, BAD_IO, BAD[/b]TIMEOUT,
void bad[b]try (FTN_ADDR [i]fa, const char *error, const int where, BINKD[/b]CONFIG [/i]config);
void good[b]try (FTN_ADDR [i]fa, char *comment, BINKD[/b]CONFIG [/i]config);
void read[b]try (FTN_ADDR [i]fa, unsigned *nok, unsigned *nbad, BINKD[/b]CONFIG [/i]config);
-void write[b]try (FTN_ADDR [i]fa, unsigned *nok, unsigned *nbad, char *comment, BINKD[/b]CONFIG [/i]config);
+void write[b]try (FTN_ADDR [i]fa, unsigned *nok, unsigned *nbad, const char *comment, BINKD[/b]CONFIG [/i]config);
void remove[b]try (FTN_ADDR [i]fa, BINKD[/b]CONFIG [/i]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 h[b]connect(int so, const char [i]host, const char *port, BINKD[/b]CONFIG [/i]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 find[b]tmp_name (char [i]s, TFILE *file, STATE *state, BINKD[/b]CONFIG [/i]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 sockaddr[b]cmp[/b]addr(const struct sockaddr [i]a, const struct sockaddr [/i]b)
return a->sa[b]family - b->sa[/b]family;

if (a->sa[b]family == AF[/b]INET)
- return (((struct sockaddr[b]in[i])a)->sin_addr.s_addr - ((struct sockaddr_in[/i])b)->sin_addr.s[/b]addr);
+ /[i] Compiler can produce a warning here, cast from sockaddr* to sockaddr_in[/i]
+ * increases required alignment. This can be ignored because objects a and
+ * b are pointing to sockaddr[b]in or sockaddr[/b]in6, determined by checking
+ [i] sa_family, so the operation is safe. [/i]/
+ return (((const struct sockaddr[b]in[i])a)->sin_addr.s_addr - ((const struct sockaddr_in[/i])b)->sin_addr.s[/b]addr);
#ifdef AF_INET6
else if (a->sa[b]family == AF[/b]INET6)
- return memcmp((char [i]) &(((struct sockaddr[b]in6[/i])a)->sin6[/b]addr),
- (char [i]) &(((struct sockaddr[b]in6[/i])b)->sin6[/b]addr),
- sizeof(((struct sockaddr[b]in6*)a)->sin6[/b]addr));
+ return memcmp(&(((const struct sockaddr[b]in6*)a)->sin6[/b]addr),
+ &(((const struct sockaddr[b]in6*)b)->sin6[/b]addr),
+ sizeof((struct sockaddr[b]in6*)0)->sin6[/b]addr);
#endif
else
{
@@ -120,10 +124,10 @@ int sockaddr[b]cmp[/b]port(const struct sockaddr [i]a, const struct sockaddr [/i]b)
return a->sa[b]family - b->sa[/b]family;

if (a->sa[b]family == AF[/b]INET)
- return (((struct sockaddr[b]in[i])a)->sin_port - ((struct sockaddr_in[/i])b)->sin[/b]port);
+ return (((const struct sockaddr[b]in[i])a)->sin_port - ((const struct sockaddr_in[/i])b)->sin[/b]port);
#ifdef AF_INET6
else if (a->sa[b]family == AF[/b]INET6)
- return (((struct sockaddr[b]in6[i])a)->sin6_port - ((struct sockaddr_in6[/i])b)->sin6[/b]port);
+ return (((const struct sockaddr[b]in6[i])a)->sin6_port - ((const struct sockaddr_in6[/i])b)->sin6[/b]port);
#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 [i]udata, char *req, char [/i]result, size[b]t res[/b]size)
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 perl[b]on_call(FTN_NODE [i]node, BINKD[/b]CONFIG *cfg, char *[/i]hosts
}
}
releaseperlsem();
+ // release memory
+ while (q)
+ {
+ FTNQ *next = q->next;
+ free(q);
+ q = next;
+ }
Log(LL[b]DBG, "perl_on[/b]call() 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 msg[b]send2 (STATE [i]state, t[/b]msg m, char *s1, char [/i]s2)
/*
* Sends a message using format string
*/
+#ifdef [b]_GNUC_[/b]
+[b]_attribute_[/b] ((format (printf, 3, 4)))
+#endif
static void msg[b]sendf (STATE [i]state, t[/b]msg m, char [/i]s,...)
{
char msg[b]text[max (MAXPATНLEN, MAX[/b]NETNAME) + 80];
@@ -1499,7 +1502,7 @@ static int ADR (STATE [i]state, char *s, int sz, BINKD_CONFIG [/i]config)
else state->bw[b]send.rel = -pn->bw[/b]send;
}
if (state->bw[b]send.abs || state->bw[/b]send.rel)
- Log (7, "Session send rate limit is %s cps or %d%%",
+ Log (7, "Session send rate limit is %s cps or %lu%%",
describe[b]rate(state->bw_send.abs), state->bw[/b]send.rel);

if (bw[b]recv_unlim) state->bw_recv.abs = state->bw[/b]recv.rel = 0;
@@ -1509,7 +1512,7 @@ static int ADR (STATE [i]state, char *s, int sz, BINKD_CONFIG [/i]config)
else state->bw[b]recv.rel = -pn->bw[/b]recv;
}
if (state->bw[b]recv.abs || state->bw[/b]recv.rel)
- Log (7, "Session recv rate limit is %s cps or %d%%",
+ Log (7, "Session recv rate limit is %s cps or %lu%%",
describe[b]rate(state->bw_recv.abs), state->bw[/b]recv.rel);
#endif

@@ -1624,7 +1627,7 @@ static int PWD (STATE [i]state, char *pwd, int sz, BINKD_CONFIG [/i]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);
msg[b]send2 (state, M_NUL, "MSG Warning: double of password is received (M[/b]PWD more one)!", 0);
return 0;
}
@@ -1809,7 +1812,7 @@ static void setup[b]rate_limit (STATE [i]state, BINKD[/b]CONFIG *config, BW [/i]bw,
perl[b]setup[/b]rlimit(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.tv[b]sec = bw->utime.tv[/b]usec = 0;
@@ -1931,7 +1934,7 @@ static int start[b]file_recv (STATE [i]state, char *args, int sz, BINKD[/b]CONFIG [/i]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 [i]state, char *args, int sz, BINKD_CONFIG [/i]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] );
}
}
/[i] Check if the file was already sent [/i]/
@@ -2344,7 +2347,7 @@ static int SKIP (STATE [i]state, char *args, int sz, BINKD_CONFIG [/i]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->n[b]sent[/b]fls; ++n)
@@ -2413,7 +2416,7 @@ static int GOT (STATE [i]state, char *args, int sz, BINKD_CONFIG [/i]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 socket[b]in, SOCKET socket_out, FTN_NODE [i]to, FTN[/b]ADDR [/i]fa,
state.io_error = 1;
if (!binkd_exit)
{
- Log (1, "select: %s (args: %i %i)", save[b]err, socket_in, tv.tv[/b]sec);
+ Log (1, "select: %s (args: %i %li)", save[b]err, socket_in, (long)tv.tv[/b]sec);
if (to)
bad[b]try (&to->fa, save_err, BAD[/b]IO, 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 [b]_GNUC_[/b]
+[b]_attribute_[/b] ((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 create[b]sem[/b]file (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 o[b]memicmp (const void [i]s1, const void [/i]s2, size[/b]t n)
int i;

for (i = 0; i < (int) n; ++i)
- if (tolower (((char [i]) s1)[i]) != tolower (((char [/i]) s2)[i]))
- return (tolower (((char [i]) s1)[i]) - tolower (((char [/i]) s2)[i]));
+ if (tolower (((const char [i]) s1)[i]) != tolower (((const char [/i]) s2)[i]))
+ return (tolower (((const char [i]) s1)[i]) - tolower (((const char [/i]) s2)[i]));

return 0;
}
@@ -555,7 +555,7 @@ char [i]parse_args (int argc, char *argv[], char *src, char [/i]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 [b]_GNUC_[/b]
+[b]_attribute_[/b] ((format (printf, 2, 0)))
+#endif
void vLog (int lev, char *s, va_list ap);
+#ifdef [b]_GNUC_[/b]
+[b]_attribute_[/b] ((format (printf, 2, 3)))
+#endif
void Log (int lev, char *s, ...);
void InitLog(int loglevel, int conlog, char [i]logpath, void [/i]first);

--
1.9.1

-End file 0001-Squashed-commits-with-various-fixes.patch-

Best Regards, Nil
--- GoldED+/LNX 1.1.5


Текущее время: 03:25. Часовой пояс GMT +4.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc. Перевод: zCarot