Skip to content

Commit 7f77b29

Browse files
committed
Proper trimming at CR/LF for RF>IS IGate.
1 parent 2fec597 commit 7f77b29

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

ax25_pad.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,9 +1578,9 @@ int ax25_get_rr (packet_t this_p, int n)
15781578
*
15791579
* Purpose: Obtain Information part of current packet.
15801580
*
1581-
* Inputs: None.
1581+
* Inputs: this_p - Packet object pointer.
15821582
*
1583-
* Outputs: paddr - Starting address is returned here.
1583+
* Outputs: paddr - Starting address of information part is returned here.
15841584
*
15851585
* Assumption: ax25_from_text or ax25_from_frame was called first.
15861586
*
@@ -1621,6 +1621,56 @@ int ax25_get_info (packet_t this_p, unsigned char **paddr)
16211621

16221622
*paddr = info_ptr;
16231623
return (info_len);
1624+
1625+
} /* end ax25_get_info */
1626+
1627+
1628+
/*------------------------------------------------------------------------------
1629+
*
1630+
* Name: ax25_cut_at_crlf
1631+
*
1632+
* Purpose: Truncate the information part at the first CR or LF.
1633+
* This is used for the RF>IS IGate function.
1634+
* CR/LF is used as record separator so we must remove it
1635+
* before packaging up packet to sending to server.
1636+
*
1637+
* Inputs: this_p - Packet object pointer.
1638+
*
1639+
* Outputs: Packet is modified in place.
1640+
*
1641+
* Returns: Number of characters removed from the end.
1642+
* 0 if not changed.
1643+
*
1644+
* Assumption: ax25_from_text or ax25_from_frame was called first.
1645+
*
1646+
*------------------------------------------------------------------------------*/
1647+
1648+
int ax25_cut_at_crlf (packet_t this_p)
1649+
{
1650+
unsigned char *info_ptr;
1651+
int info_len;
1652+
int j;
1653+
1654+
1655+
assert (this_p->magic1 == MAGIC);
1656+
assert (this_p->magic2 == MAGIC);
1657+
1658+
info_len = ax25_get_info (this_p, &info_ptr);
1659+
1660+
// Can't use strchr because there is potential of nul character.
1661+
1662+
for (j = 0; j < info_len; j++) {
1663+
1664+
if (info_ptr[j] == '\r' || info_ptr[j] == '\n') {
1665+
1666+
int chop = info_len - j;
1667+
1668+
this_p->frame_len -= chop;
1669+
return (chop);
1670+
}
1671+
}
1672+
1673+
return (0);
16241674
}
16251675

16261676

ax25_pad.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ extern int ax25_get_first_not_repeated(packet_t pp);
397397
extern int ax25_get_rr (packet_t this_p, int n);
398398

399399
extern int ax25_get_info (packet_t pp, unsigned char **paddr);
400+
extern int ax25_cut_at_crlf (packet_t this_p);
400401

401402
extern void ax25_set_nextp (packet_t this_p, packet_t next_p);
402403

igate.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ void igate_send_rec_packet (int chan, packet_t recv_pp)
870870
packet_t pp;
871871
int n;
872872
unsigned char *pinfo;
873-
char *p;
874873
int info_len;
875874

876875

@@ -995,33 +994,25 @@ void igate_send_rec_packet (int chan, packet_t recv_pp)
995994

996995
/*
997996
* Cut the information part at the first CR or LF.
997+
* This is required because CR/LF is used as record separator when sending to server.
998998
* Do NOT trim trailing spaces.
999+
* Starting in 1.4 we preserve any nul characters in the information part.
9991000
*/
10001001

1001-
info_len = ax25_get_info (pp, &pinfo);
1002-
(void)(info_len);
1003-
1004-
if ((p = strchr ((char*)pinfo, '\r')) != NULL) {
1002+
if (ax25_cut_at_crlf (pp) > 0) {
10051003
if (s_debug >= 1) {
10061004
text_color_set(DW_COLOR_DEBUG);
10071005
dw_printf ("Rx IGate: Truncated information part at CR.\n");
10081006
}
1009-
*p = '\0';
10101007
}
10111008

1012-
if ((p = strchr ((char*)pinfo, '\n')) != NULL) {
1013-
if (s_debug >= 1) {
1014-
text_color_set(DW_COLOR_DEBUG);
1015-
dw_printf ("Rx IGate: Truncated information part at LF.\n");
1016-
}
1017-
*p = '\0';
1018-
}
1009+
info_len = ax25_get_info (pp, &pinfo);
10191010

10201011

10211012
/*
10221013
* Someone around here occasionally sends a packet with no information part.
10231014
*/
1024-
if (strlen((char*)pinfo) == 0) {
1015+
if (info_len == 0) {
10251016

10261017
if (s_debug >= 1) {
10271018
text_color_set(DW_COLOR_DEBUG);

0 commit comments

Comments
 (0)