1 /*
2 bug-3495411.c
3 */
4
5 #include <testfwk.h>
6
7 #ifdef __SDCC
8 #pragma std_c99
9 #pragma disable_warning 85
10 #pragma disable_warning 88
11 #endif
12
13 // Type defines
14 #define UCHAR unsigned char
15 #define USHORT unsigned short
16 #define ULONG unsigned long
17 //#define BOOLEAN unsigned char
18 #define BOOLEAN _Bool
19
20 #define PCHAR unsigned char *
21 #define PSHORT unsigned short *
22 #define PLONG unsigned long *
23
24 #ifndef NULL
25 #define NULL (void *)0
26 #endif
27
28 #define TRUE 1
29 #define FALSE 0
30
31 #define IP_ALEN 4
32 #define RTP_SSRC_LEN 4
33 #define MAX_USER_NAME_LEN 32
34 #define MAX_USER_NUMBER_LEN 32
35 #define MAX_TAG_LEN 16
36
37 typedef struct _CALL_TIME
38 {
39 UCHAR iSec;
40 UCHAR iMin;
41 UCHAR iHour;
42 } CALL_TIME;
43
44 struct ucb
45 {
46 UCHAR iState;
47 USHORT sSrcPort;
48 UCHAR iBankOffset; /* Bank offset of call back function */
49 USHORT sCallBack; /* Address of call back function */
50 USHORT sDstPort;
51 UCHAR pDstIP[IP_ALEN];
52 USHORT sLen;
53 };
54
55 typedef struct ucb * UDP_SOCKET;
56
57 typedef struct sip_lcb * SIP_LCB_HANDLE;
58 typedef struct sip_tcb * SIP_TCB_HANDLE;
59
60 struct sip_tcb
61 {
62 UCHAR iState;
63 UCHAR iMethod;
64 UCHAR pDstIP[IP_ALEN];
65 USHORT sDstPort;
66 UCHAR iTimer0;
67 UCHAR iTimer1;
68 UCHAR iTimer2;
69 BOOLEAN b100rel;
70 PCHAR pBranch;
71 PCHAR pData;
72 SIP_LCB_HANDLE pLcb;
73 };
74
75 struct sip_lcb
76 {
77 UCHAR iState; // State of this line
78 BOOLEAN bCallee; // Caller or callee
79 UCHAR iTimer; // No anser timer
80 UCHAR iRemoteRb; // ringback tone type
81 BOOLEAN bHolding;
82 BOOLEAN bEarlyDlg; // already received a 1xx response
83
84 UCHAR iVoiceCoder; // voice coder used by this line
85 BOOLEAN bVad;
86 UCHAR iRemoteMode; // remote voice transmission mode
87 UCHAR pRtpDstIP[IP_ALEN]; // RTP dst IP
88 USHORT sRtpDstPort; // RTP dst port
89 UCHAR iCoderPayload; // Peer's coder payload
90 UCHAR iDtmfPayload; // Peer's DTMF payload
91
92 UCHAR iLocalMode; // local voice transmission mode
93 UCHAR iSdpType;
94 UCHAR pSdpSessionId[9];
95 ULONG lSdpVersion;
96 UDP_SOCKET pRtpSocket;
97 USHORT sRtpPort; // local RTP port
98 USHORT sRtpSeq; // RTP sequence
99 UCHAR pRtpSSRC[RTP_SSRC_LEN];
100 UCHAR pRtpDstSSRC[RTP_SSRC_LEN];
101 ULONG lRtpTimeStamp; // RTP timestamp
102 ULONG lRtpOffset;
103 BOOLEAN bVoiceStart;
104 BOOLEAN bSendingKey; // RFC2833 send key
105 UCHAR iSendKey; // Key being sent
106 USHORT sSendKeyLen; // Duration in timestamp
107 BOOLEAN bKeyRecved;
108 UCHAR pKeyTimeStamp[4];
109
110 UCHAR pDstIP[IP_ALEN]; // Dst IP of this call
111 USHORT sDstPort; // Dst port of this call
112 ULONG lRseq; // RSEQ for PRACK
113 ULONG lCurSeq; // Current sequence of this call
114 ULONG lInvSeq; // Sequence of INVITE request
115 PCHAR pInvUri; // Original request Uri of this call
116 PCHAR pReqUri; // Request URI of this call
117 PCHAR pBranch; // Invite branch
118 PCHAR pCallId; // Call-ID header of this call
119 PCHAR pFrom; // From header of this call
120 PCHAR pTo; // To header
121 PCHAR pFromTag; // Local tag
122 PCHAR pToTag; // Remote tag
123 PCHAR pProxyAuth; // Proxy-Authenticate information
124 PCHAR pWWWAuth; // WWW-Authenticate information
125 PCHAR pRoute; // Route header to be included in request
126 PCHAR pInvHeader; // Invite header to be included in response
127 SIP_TCB_HANDLE pInvTcb; // Transaction control block of INVITE request
128
129 UCHAR pRespDstIP[IP_ALEN];
130 USHORT sRespDstPort;
131 PCHAR pReferredBy;
132 PCHAR pReplaces;
133 UCHAR iXferPart; // which role do we play? transferor, transferee or transfer-to?
134
135 UCHAR iRefresher;
136 ULONG lSessionExpires;
137 ULONG lSessionTimer;
138 ULONG lMinSE;
139
140 UCHAR pPeerName[MAX_USER_NAME_LEN];
141 UCHAR pPeerNumber[MAX_USER_NUMBER_LEN];
142 CALL_TIME ct;
143 UCHAR pKeyOut[MAX_USER_NUMBER_LEN];
144 UCHAR iKeyIndex;
145 BOOLEAN bMemCall;
146 };
147
148 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
149 __xdata struct sip_lcb l;
150 extern SIP_LCB_HANDLE Sip_pCurLcb = &l;
151
line_start(PCHAR pDst)152 void line_start(PCHAR pDst) {}
sip_add_local_uri(BOOLEAN bIP,BOOLEAN bPort)153 void sip_add_local_uri(BOOLEAN bIP, BOOLEAN bPort) {}
sip_new_token(PCHAR pDst,UCHAR iLen)154 void sip_new_token(PCHAR pDst, UCHAR iLen) {}
sip_add_token(PCHAR pToken,PCHAR pValue)155 void sip_add_token(PCHAR pToken, PCHAR pValue) {}
dummy_free(void * p)156 void dummy_free(void *p) {}
heap_save_str(PCHAR pStr)157 PCHAR heap_save_str(PCHAR pStr) { return ((PCHAR) 42);}
158 BOOLEAN Sys_bRegister;
159 const UCHAR _cTokenTag[] = "";
160
sip_new_from()161 void sip_new_from()
162 {
163 #ifdef __SDCC_mcs51
164 UCHAR pBuf[64];
165 #else
166 UCHAR pBuf[128];
167 #endif
168 UCHAR pTag[MAX_TAG_LEN+1];
169
170 line_start(pBuf);
171 sip_add_local_uri(!Sys_bRegister, FALSE);
172 sip_new_token(pTag, MAX_TAG_LEN);
173 sip_add_token(_cTokenTag, pTag);
174 dummy_free(Sip_pCurLcb->pFrom);
175 Sip_pCurLcb->pFrom = heap_save_str(pBuf);
176 dummy_free(Sip_pCurLcb->pFromTag);
177 Sip_pCurLcb->pFromTag = heap_save_str(pTag);
178 }
179 #endif
180
181 void
testBug(void)182 testBug (void)
183 {
184 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
185 l.pFrom = (PCHAR) 23;
186 sip_new_from();
187 ASSERT (l.pFrom == (PCHAR) 42);
188 #endif
189 }
190
191