Добро пожаловать, Гость. Пожалуйста авторизуйтесь здесь.
FGHIGate на GaNJa NeTWoRK ST@Ti0N - Просмотр сообщения в эхоконференции RU.BINKD
Введите FGHI ссылку:


Присутствуют сообщения из эхоконференции RU.BINKD с датами от 14 Jul 13 17:53:22 до 25 Aug 24 19:42:02, всего сообщений: 1947
Ответить на сообщение К списку сообщений Предыдущее сообщение Следующее сообщение
= Сообщение: 1916 из 1947 ========================================= RU.BINKD =
От   : Nil A                            2:5015/46          07 Mar 24 07:02:22
Кому : All                                                 07 Mar 24 07:02:22
Тема : Накопившиеся патчи
FGHI : area://RU.BINKD?msgid=2:5015/46+65e93fcd
= Кодировка сообщения определена как: CP866 ==================================
==============================================================================
Hello, 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: [PATCH] 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_NODE *node, BINKD_CONFIG *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 (FTN_NODE *node, BINKD_CONFIG *config)
       }
       if (!binkd_exit)
       {
-        Log (1, "connection to %s failed");
+        Log (1, "connection to %s failed", host);
         /* bad_try (&node->fa, "exec error", BAD_CALL, 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 *q_scan_boxes (FTNQ *q, FTN_ADDR *fa, int n, int to, BINKD_CONFIG *config)
         strnzcpy (buf, config->bfilebox, sizeof (buf));
         strnzcat (buf, PATH_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_node (FTN_ADDR *fa, time_t hold_until, BINKD_CONFIG *config)
   }
 }

-void write_try (FTN_ADDR *fa, unsigned *nok, unsigned *nbad, char *comment, BINKD_CONFIG *config)
+void write_try (FTN_ADDR *fa, unsigned *nok, unsigned *nbad, const char *comment, BINKD_CONFIG *config)
 {
   char buf[MAXPATHLEN + 1];

@@ -1117,7 +1117,7 @@ void bad_try (FTN_ADDR *fa, const char *error, const int where, BINKD_CONFIG *co
     nok = nbad = 0;
     hold_node (fa, safe_time() + config->hold, config);
   }
-  write_try (fa, &nok, &nbad, (char *) error, config);
+  write_try (fa, &nok, &nbad, error, config);
 }

 void good_try (FTN_ADDR *fa, char *comment, BINKD_CONFIG *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_try_type { BAD_NA, BAD_CALL, BAD_MERR, BAD_MBSY, BAD_IO, BAD_TIMEOUT,
 void bad_try (FTN_ADDR *fa, const char *error, const int where, BINKD_CONFIG *config);
 void good_try (FTN_ADDR *fa, char *comment, BINKD_CONFIG *config);
 void read_try (FTN_ADDR *fa, unsigned *nok, unsigned *nbad, BINKD_CONFIG *config);
-void write_try (FTN_ADDR *fa, unsigned *nok, unsigned *nbad, char *comment, BINKD_CONFIG *config);
+void write_try (FTN_ADDR *fa, unsigned *nok, unsigned *nbad, const char *comment, BINKD_CONFIG *config);
 void remove_try (FTN_ADDR *fa, BINKD_CONFIG *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_connect(int so, const char *host, const char *port, BINKD_CONFIG *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(aiHead);
                                        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_tmp_name (char *s, TFILE *file, STATE *state, BINKD_CONFIG *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_cmp_addr(const struct sockaddr *a, const struct sockaddr *b)
     return a->sa_family - b->sa_family;

   if (a->sa_family == AF_INET)
-    return (((struct sockaddr_in*)a)->sin_addr.s_addr - ((struct sockaddr_in*)b)->sin_addr.s_addr);
+    /* 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 sockaddr_in or sockaddr_in6, determined by checking
+     * sa_family, so the operation is safe. */
+    return (((const struct sockaddr_in*)a)->sin_addr.s_addr - ((const struct sockaddr_in*)b)->sin_addr.s_addr);
 #ifdef AF_INET6
   else if (a->sa_family == AF_INET6)
-    return memcmp((char *) &(((struct sockaddr_in6*)a)->sin6_addr),
-                 (char *) &(((struct sockaddr_in6*)b)->sin6_addr),
-                 sizeof(((struct sockaddr_in6*)a)->sin6_addr));
+    return memcmp(&(((const struct sockaddr_in6*)a)->sin6_addr),
+      &(((const struct sockaddr_in6*)b)->sin6_addr),
+      sizeof((struct sockaddr_in6*)0)->sin6_addr);
 #endif
   else
   {
@@ -120,10 +124,10 @@ int sockaddr_cmp_port(const struct sockaddr *a, const struct sockaddr *b)
     return a->sa_family - b->sa_family;

   if (a->sa_family == AF_INET)
-    return (((struct sockaddr_in*)a)->sin_port - ((struct sockaddr_in*)b)->sin_port);
+    return (((const struct sockaddr_in*)a)->sin_port - ((const struct sockaddr_in*)b)->sin_port);
 #ifdef AF_INET6
   else if (a->sa_family == AF_INET6)
-    return (((struct sockaddr_in6*)a)->sin6_port - ((struct sockaddr_in6*)b)->sin6_port);
+    return (((const struct sockaddr_in6*)a)->sin6_port - ((const struct sockaddr_in6*)b)->sin6_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 *udata, char *req, char *result, size_t res_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_on_call(FTN_NODE *node, BINKD_CONFIG *cfg, char **hosts
       }
     }
     releaseperlsem();
+    // release memory
+    while (q)
+    {
+        FTNQ *next = q->next;
+        free(q);
+        q = next;
+    }
     Log(LL_DBG, "perl_on_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_send2 (STATE *state, t_msg m, char *s1, char *s2)
 /*
  * Sends a message using format string
  */
+#ifdef __GNUC__
+__attribute__ ((format (printf, 3, 4)))
+#endif
 static void msg_sendf (STATE *state, t_msg m, char *s,...)
 {
   char msg_text[max (MAXPATHLEN, MAX_NETNAME) + 80];
@@ -1499,7 +1502,7 @@ static int ADR (STATE *state, char *s, int sz, BINKD_CONFIG *config)
     else state->bw_send.rel = -pn->bw_send;
   }
   if (state->bw_send.abs || state->bw_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_rate(state->bw_send.abs), state->bw_send.rel);

   if (bw_recv_unlim) state->bw_recv.abs = state->bw_recv.rel = 0;
@@ -1509,7 +1512,7 @@ static int ADR (STATE *state, char *s, int sz, BINKD_CONFIG *config)
     else state->bw_recv.rel = -pn->bw_recv;
   }
   if (state->bw_recv.abs || state->bw_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_rate(state->bw_recv.abs), state->bw_recv.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);
     msg_send2 (state, M_NUL, "MSG Warning: double of password is received (M_PWD more one)!", 0);
     return 0;
   }
@@ -1809,7 +1812,7 @@ static void setup_rate_limit (STATE *state, BINKD_CONFIG *config, BW *bw,
   perl_setup_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_sec = bw->utime.tv_usec = 0;
@@ -1931,7 +1934,7 @@ static int start_file_recv (STATE *state, char *args, int sz, BINKD_CONFIG *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->n_sent_fls; ++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 socket_in, SOCKET socket_out, FTN_NODE *to, FTN_ADDR *fa,
         state.io_error = 1;
         if (!binkd_exit)
         {
-          Log (1, "select: %s (args: %i %i)", save_err, socket_in, tv.tv_sec);
+          Log (1, "select: %s (args: %i %li)", save_err, socket_in, (long)tv.tv_sec);
           if (to)
             bad_try (&to->fa, save_err, BAD_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 __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 create_sem_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_memicmp (const void *s1, const void *s2, size_t n)
   int i;

   for (i = 0; i < (int) n; ++i)
-    if (tolower (((char *) s1)[i]) != tolower (((char *) s2)[i]))
-      return (tolower (((char *) s1)[i]) - tolower (((char *) s2)[i]));
+    if (tolower (((const char *) s1)[i]) != tolower (((const char *) s2)[i]))
+      return (tolower (((const char *) s1)[i]) - 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
* Origin: Linux 2.6.32-042stab145.3 (2:5015/46)

К главной странице гейта
Powered by NoSFeRaTU`s FGHIGate
Открытие страницы: 0.127089 секунды