Played with this some more. Got atftpd rebuilt with debugging symbols
left in, then re-ran under gdb and watching packet captures. Suddenly
it succeeds. I've got a nasty suspicion this is actually a timing issue,
not a ports getting confused issue.


A couple small refinements I ran into when trying to diagnose this
problem. First blob is cleanup, I can tell atftp was originally written
by a student, since this is one of those classic bogo-sort type
weaknesses. Second blob is cleanup, another classic example of hard to
check what is going on situations. Third blob is an actual lurking bug,
the condition isn't exercied in the original code, but will explode
depending on future modifications.
-----8<-----------------------------------------------------------8<-----
--- tftpd_mcast.c.orig  2003-04-24 17:16:19.000000000 -0700
+++ tftpd_mcast.c       2011-04-27 21:16:24.000000000 -0700
@@ -107,7 +107,7 @@
 {
      char *ip;
      char *port;
-     struct tid *current = NULL;
+     struct tid **pcur = &tid_list;
      struct tid *tmp = NULL;
 
      while (1)
@@ -128,16 +128,8 @@
               tmp->port = (short)atoi(port);
               tmp->used = 0;
               tmp->next = NULL;
-              if (tid_list == NULL)
-              {
-                   tid_list = tmp;
-                   current = tid_list;
-              }
-              else
-              {
-                   current->next = tmp;
-                   current = tmp;
-              }
+               *pcur = tmp;
+               pcur = &tmp->next;
          }
      }
 }
--- tftpd.c.orig        2011-04-15 20:35:31.000000000 -0700
+++ tftpd.c     2011-04-15 21:38:49.000000000 -0700
@@ -60,7 +60,6 @@
 char directory[MAXLEN] = "/srv/tftp/";
 int retry_timeout = S_TIMEOUT;
 
-int on = 1;
 int listen_local = 0;
 
 int tftpd_daemon = 0;           /* By default we are started by inetd */
@@ -646,7 +645,8 @@
              I was unable to find a kernel option or /proc/sys flag to make 
the kernel pay attention to 
              these requests, so the workaround is to force listening on the 
local address. */
           if (listen_local == 1)
-          { 
+         {
+               const int on = 1;
                logger(LOG_INFO, "forcing socket to listen on local address");
                if (setsockopt(data->sockfd, SOL_SOCKET, SO_BROADCAST, &on, 
sizeof(on)) != 0) {
                   logger(LOG_ERR, "setsockopt: %s", strerror(errno));
--- tftpd.c.orig        2011-04-15 23:07:20.000000000 -0700
+++ tftpd.c     2011-04-15 23:06:34.000000000 -0700
@@ -657,7 +657,7 @@
                logger(LOG_INFO, "socket may listen on any address, including 
broadcast");
           }
 
-          if (data->sockfd > 0)
+          if (data->sockfd >= 0)
           {
                /* bind the socket to the interface */
                if (bind(data->sockfd, (struct sockaddr *)&to, len) == -1)
-----8<-----------------------------------------------------------8<-----


-- 
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         e...@gremlin.m5p.com PGP F6B23DE0         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
2477\___\_|_/DC21 03A0 5D61 985B <-PGP-> F2BE 6526 ABD2 F6B2\_|_/___/3DE0





-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to