From: Mazet Laurent Date: Tue, 25 Mar 2025 03:25:43 +0000 (+0100) Subject: fix padding X-Git-Tag: v1.0~104 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=23f71e93c2d1f2ad2f81fdcccaf038f4c3d042c3;p=morep.git fix padding --- diff --git a/morep.c b/morep.c index fd1f6c9..8f3f61d 100644 --- a/morep.c +++ b/morep.c @@ -329,7 +329,13 @@ int MOREP_Send (int index, uint8_t msgtype, int len) memcpy (morep->tx_buffer + 16, (void *) &msglen, 2); VERBOSE (morep, DEBUG, PRINTF ("sent preamble: "); int i; for (i = 0; i < 18; i++) printf ("%02x:", morep->tx_buffer[i]); printf ("\n")); - int rc = sendto (morep->sock, morep->tx_buffer, len + 18, 0, NULL, 0); + int txlen = len + 18; + if (txlen < 64) { + VERBOSE (morep, DEBUG, PRINTF ("need padding: %d bytes\n", 64 - txlen)); + memset (morep->tx_buffer + txlen, 0, 64 - txlen); + txlen = 64; + } + int rc = sendto (morep->sock, morep->tx_buffer, txlen, 0, NULL, 0); return (rc < 18) ? -1 : seqnum; } @@ -372,7 +378,10 @@ int MOREP_Receive (int index, uint8_t *msgtype) uint16_t msglen = 0; memcpy ((void *) &msglen, morep->rx_buffer + 16, 2); morep->rxlen = htons (msglen); - if (morep->rxlen != len - 18) { + if (morep->rxlen < 64 - 18) { + VERBOSE (morep, DEBUG, PRINTF ("padding of %d bytes\n", 64 - 18 - morep->rxlen)); + VERBOSE (morep, DEBUG, int i; for (i = morep->rxlen + 18; i < 64; i++) if (morep->rx_buffer[i] != 0) { VERBOSE (morep, WARNING, PRINTF ("incorrect padding\n")); break; }); + } else if (morep->rxlen != len - 18) { VERBOSE (morep, WARNING, PRINTF ("incorrect size (%d/%d)\n", morep->rxlen, len - 18)); morep->rxlen = len - 18; } @@ -397,4 +406,4 @@ int MOREP_Close (int index) return 0; } -/* vi:set tabstop=4 expandtab shiftwidth=4: this line set vi mode*/ +/* vim: set ts=4 sw=4 et: */