tags 242497 + patch
thanks

I've atteched two different patches to stop aprsd from munging
MIC-e packets. The patches are originally from Tapio, OH2KKU.

The first one (aprsd-patch-tested.txt) is quite simple, and has 
been tested on few digis here in Finland. It works fine for us, 
but it still filters some non-printable characters and might 
still break some cases.

The second patch (aprsd-patch-untested.txt) is currently untested, 
but shouldn't break any valid packets as it only filters (rejects) 
packets containing NULL (0x00) and truncates packets to first 
occurence of CR or LF, allowing all other characters.

One of these (or some similar) patches should probably be included 
in upstream (sf.net) version too, as this seems to be quite common 
problem.

-kimju, OH3GNU
--- ax25socket.cpp      2003-05-29 21:26:33.000000000 +0300
+++ ax25socket_new.cpp  2005-05-05 23:43:59.000000000 +0300
@@ -288,8 +288,12 @@
     // No rewriting for mic-e frames because aprsd does this later
     sprintf ((char*)buf1, "%s>%s%s:", from, to, digis);
     l = strlen ((char*)buf1);
-    for (i = 0; i < len; i++, l++) {
-        buf1[l] = (isprint (buf[i])) ? buf[i] : ' ';    // keep it clean
+    for (i = 0; i < len; i++) {
+        /* preserve mic-e non-printable characters. */
+        if (buf[i] >= 0x1c && buf[i] <= 0x7f) {
+            buf1[l] = buf[i];
+            l++;
+        }
     }
 
     buf1[l++] = 0x0d;
--- ax25socket.cpp.orig 2003-05-29 21:26:33.000000000 +0300
+++ ax25socket.cpp      2005-05-08 19:37:23.000000000 +0300
@@ -237,6 +237,9 @@
     char from[10], to[10], digis[100];
     int i, hadlast, l;
     char tmp[15];
+    unsigned char prebuf[1000];
+
+    prebuf[0] = '\0';
 
     *buf1 = '\0';
     *outbuf = buf1;
@@ -286,16 +289,29 @@
     }
 
     // No rewriting for mic-e frames because aprsd does this later
-    sprintf ((char*)buf1, "%s>%s%s:", from, to, digis);
-    l = strlen ((char*)buf1);
-    for (i = 0; i < len; i++, l++) {
-        buf1[l] = (isprint (buf[i])) ? buf[i] : ' ';    // keep it clean
+    sprintf ((char*)prebuf, "%s>%s%s:", from, to, digis);
+    l = strlen ((char*)prebuf);
+    for (i = 0; i < len; i++) {
+        if (buf[i] == 0x00)
+            /* we don't like nulls so we just throw the packet away */
+            return;
+        else if (buf[i] == 0x0a || buf[i] == 0x0d)
+            /* truncate the packet at the first CR or LF */
+            break;
+        else {
+            /* let everything else pass */
+            prebuf[l] = buf[i];
+            l++;
+        }
     }
 
-    buf1[l++] = 0x0d;
-    buf1[l++] = 0x0a;
+    prebuf[l++] = 0x0d;
+    prebuf[l++] = 0x0a;
+    prebuf[l] = '\0';
+
+    strncpy(buf1, prebuf, 999);
+    buf1[999] = '\0';
 
-    buf1[l] = '\0';
     return;
 }
 

Reply via email to