~ubuntu-branches/ubuntu/jaunty/sip-tester/jaunty

« back to all changes in this revision

Viewing changes to call.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Nico Golde
  • Date: 2008-05-04 13:58:41 UTC
  • mfrom: (3.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080504135841-1oykxb0mtrrn7pfu
Tags: 2.0.1-1.2
* Non-maintainer upload by the Security Team.
* CVE-2008-1959: Fix stack-based buffer overflow in the
  get_remote_video_port_media function
* CVE-2008-2085: Fix stack-baseed buffer overflow in the
  get_remote_ip_media and get_remote_ipv6_media
  functions which lead to arbitrary code execution (Closes: #479039).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *           From Hewlett Packard Company.
18
18
 */
19
19
 
 
20
#ifndef __CALL__
 
21
#define __CALL__
 
22
 
20
23
#include <map>
 
24
#include <list>
21
25
#include <sys/types.h>
22
26
#include <sys/socket.h>
23
27
#include <string.h>
25
29
#ifdef _USE_OPENSSL
26
30
#include "sslcommon.h"
27
31
#endif
 
32
#ifdef PCAPPLAY
 
33
#include "send_packets.h"
 
34
#endif
28
35
 
 
36
#ifndef MAX
29
37
#define MAX(a, b) ((a) > (b) ? (a) : (b))
 
38
#endif
30
39
#define MAX_HEADER_LEN 2049
31
40
#define UDP_MAX_RETRANS_INVITE_TRANSACTION 5
32
41
#define UDP_MAX_RETRANS_NON_INVITE_TRANSACTION 9
36
45
#define SIP_TRANSACTION_TIMEOUT 32000
37
46
 
38
47
#ifdef __HPUX
39
 
  extern int createAuthHeader(char * user, char * password, char * method, char * uri, char * msgbody, char * auth, char * result);
 
48
  extern int createAuthHeader(char * user, char * password, char * method, char * uri, char * msgbody, char * auth, char * aka_OP, char * aka_AMF, char * aka_K, char * result);
40
49
#else
41
 
  extern "C" { extern int createAuthHeader(char * user, char * password, char * method, char * uri, char * msgbody, char * auth, char * result);  }
 
50
  extern "C" { extern int createAuthHeader(char * user, char * password, char * method, char * uri, char * msgbody, char * auth, char * aka_OP, char * aka_AMF, char * aka_K, char * result);  }
42
51
#endif
43
52
 
 
53
/* Forward declaration of call, so that we can define the call_list iterator
 
54
 * that is referenced from call. */
 
55
class call;
 
56
 
 
57
typedef std::list<call *> call_list;
 
58
 
 
59
/* This arrangement of wheels lets us support up to 32 bit timers.
 
60
 *
 
61
 * If we were to put a minimum bound on timer_resol (or do some kind of dynamic
 
62
 * allocation), then we could reduce the level one order by a factor of
 
63
 * timer_resol. */
 
64
#define LEVEL_ONE_ORDER 12
 
65
#define LEVEL_TWO_ORDER 10
 
66
#define LEVEL_THREE_ORDER 10
 
67
#define LEVEL_ONE_SLOTS (1 << LEVEL_ONE_ORDER)
 
68
#define LEVEL_TWO_SLOTS (1 << LEVEL_TWO_ORDER)
 
69
#define LEVEL_THREE_SLOTS (1 << LEVEL_THREE_ORDER)
 
70
 
 
71
/* A time wheel structure as defined in Varghese and Lauck's 1996 journal
 
72
 * article (based on their 1987 SOSP paper). */
 
73
class timewheel {
 
74
public:
 
75
        timewheel();
 
76
 
 
77
        int expire_paused_calls();
 
78
        /* Add a paused call and increment count. */
 
79
        void add_paused_call(call *call, bool increment);
 
80
        void remove_paused_call(call *call);
 
81
        int size();
 
82
 
 
83
private:
 
84
        /* How many calls are in this wheel. */
 
85
        int count;
 
86
 
 
87
        unsigned int wheel_base;
 
88
 
 
89
        /* The actual wheels. */
 
90
        call_list wheel_one[LEVEL_ONE_SLOTS];
 
91
        call_list wheel_two[LEVEL_TWO_SLOTS];
 
92
        call_list wheel_three[LEVEL_THREE_SLOTS];
 
93
 
 
94
        /* Calls that are paused indefinitely. */
 
95
        call_list forever_list;
 
96
 
 
97
        /* Turn a call into a list (based on wakeup). */
 
98
        call_list *call2list(call *call);
 
99
};
 
100
 
44
101
class call {
45
 
 
46
102
public:
47
103
  char         * id;
48
104
  unsigned int   number;
 
105
  unsigned int   tdm_map_number;
49
106
 
50
 
  unsigned int   msg_index;
 
107
  int           msg_index;
51
108
 
52
109
  /* Last message sent from scenario step (retransmitions do not
53
110
   * change this index. Only message sent from the scenario
54
111
   * are kept in this index.) */
55
 
  unsigned int   last_send_index;
 
112
  int            last_send_index;
56
113
  char         * last_send_msg;
57
114
 
58
115
  /* Last received message (expected,  not optional, and not 
59
116
   * retransmitted) and the associated hash. Stills setted until a new
60
117
   * scenario steps sends a message */
61
118
  unsigned long    last_recv_hash;
62
 
  unsigned int     last_recv_index;
 
119
  int              last_recv_index;
63
120
  char           * last_recv_msg;
64
121
 
65
122
  /* Recv message characteristics when we sent a valid message
69
126
  unsigned long  recv_retrans_hash;
70
127
  unsigned int   recv_retrans_recv_index;
71
128
  unsigned int   recv_retrans_send_index;
 
129
  unsigned int   recv_timeout;
72
130
 
73
131
  /* holds the route set */
74
132
  char         * dialog_route_set;
78
136
  unsigned int   cseq;
79
137
 
80
138
#ifdef PCAPPLAY
81
 
  /* remote media information */
82
 
  uint32_t remote_ip_media;
83
 
  uint16_t remote_port_media;
 
139
  int hasMediaInformation;
84
140
  pthread_t media_thread;
 
141
  play_args_t play_args_a;
 
142
  play_args_t play_args_v;
85
143
#endif
86
144
 
87
145
  
92
150
#endif
93
151
 
94
152
  unsigned int   next_retrans;
95
 
  unsigned int   nb_retrans;
 
153
  int            nb_retrans;
96
154
  unsigned int   nb_last_delay;
97
155
 
98
156
  unsigned int   paused_until;
99
157
 
100
158
  unsigned long  start_time;
101
 
  unsigned long  start_time_rtd;
 
159
  unsigned long  start_time_rtd[MAX_RTD_INFO_LENGTH];
102
160
 
103
 
  bool           rtd_done;
 
161
  bool           rtd_done[MAX_RTD_INFO_LENGTH];
104
162
  
105
 
  char           peer_tag[MAX_HEADER_LEN];
 
163
  char           *peer_tag;
106
164
  
107
165
  int            call_socket;
108
166
  int            call_remote_socket;
149
207
 
150
208
  /* rc == true means call not deleted by processing */
151
209
  bool run(); 
152
 
  bool process_incomming(char * msg);
 
210
  void formatNextReqUrl (char* next_req_url);
 
211
  void computeRouteSetAndRemoteTargetUri (char* rrList, char* contact, bool bRequestIncoming);
 
212
  bool matches_scenario(unsigned int index, int reply_code, char * request, char * responsecseqmethod);
 
213
  bool process_incoming(char * msg);
153
214
 
154
215
  T_ActionResult executeAction(char * msg, int scenarioIndex);
155
 
  void  extractSubMessage(char * msg, char * matchingString, char* result);
 
216
  void  extractSubMessage(char * msg, char * matchingString, char* result, bool case_indep, 
 
217
                                                             int occurrence, bool headers); 
156
218
  bool  rejectCall();
157
 
  
 
219
 
 
220
  // Get parameters from a [keyword]
 
221
  void getHexStringParam(char * dest, char * src, int * len);
 
222
  char* getKeywordParam(char * src, char * param, char * output);
 
223
 
158
224
  // P_index use for message index in scenario and ctrl of CRLF
159
225
  // P_index = -2 No ctrl of CRLF
160
226
  // P_index = -1 Add crlf to end of message
166
232
                                      // received from the twin socket
167
233
                                      // used for example to cancel the call
168
234
                                      // of the third party
 
235
  bool  check_peer_src(char* msg,
 
236
                int search_index);    // 3pcc extended mode:check if 
 
237
                                      // the twin message received
 
238
                                      // comes from the expected sender
169
239
  int   sendBuffer(char *buf);        // send a message out of a scenario 
170
240
                                      // execution
171
241
  int   checkAutomaticResponseMode(char * P_recv);
172
 
  void  automaticResponseMode(int P_case, char* P_recv);
 
242
  bool  automaticResponseMode(int P_case, char* P_recv);
173
243
 
174
244
#ifdef __3PCC__
175
245
  int   sendCmdMessage(int index); // 3PCC
188
258
  static void readInputFileContents(const char* fileName);
189
259
  static void dumpFileContents(void);
190
260
 
 
261
  static void getFieldFromInputFile(const char* fieldName, unsigned int lineNum, char*& dest);
 
262
  static void getIpFieldFromInputFile(int fieldNr, int lineNum, char *dest);
 
263
  static int  m_counter; // used for sequential access
 
264
 
 
265
  /* Is this call paused or running? */
 
266
  bool running;
 
267
  /* If we are running, the iterator to remove us from the running list. */
 
268
  call_list::iterator runit;
 
269
  /* If we are paused, the iterator to remove us from the paused list. */
 
270
  call_list::iterator pauseit;
 
271
 
191
272
private:
192
273
  /* rc == true means call not deleted by processing */
193
274
  bool next();
194
275
  bool process_unexpected(char * msg);
 
276
  void do_bookkeeping(int index);
195
277
 
196
278
  void  extract_cseq_method (char* responseCseq, char* msg);
197
279
 
200
282
  void   connect_socket_if_needed();
201
283
 
202
284
  char * compute_cseq(char * src);
 
285
  char * get_header_field_code(char * msg, char * code);
203
286
  char * get_last_header(char * name);
204
287
  char * get_header_content(char* message, char * name);
 
288
  char * get_header(char* message, char * name, bool content);
205
289
 
206
290
  static InputFileUsage m_usage;
207
 
  static int            m_counter; // used for sequential access
208
291
 
209
292
  int    m_localLineNumber;
210
293
 
211
294
  bool   use_ipv6;
212
295
 
213
 
  static void getFieldFromInputFile(const char* fieldName, int lineNum, char*& dest);
 
296
  void   get_remote_media_addr(char * message);
214
297
 
215
298
#ifdef _USE_OPENSSL
216
299
  SSL_CTX   *m_ctx_ssl ;
217
300
  BIO       *m_bio     ;
218
 
#endif  
219
 
 
 
301
#endif
220
302
};
221
303
 
222
304
/* Call contexts interface */
223
305
 
224
306
typedef std::map<std::string, call *> call_map;
225
307
call_map * get_calls();
 
308
call_list * get_running_calls();
226
309
 
227
 
#ifdef _USE_OPENSSL
228
 
  call      * add_call(char * call_id , int P_pollset_indx, bool ipv6 = false);
229
 
#endif  
 
310
call * add_call(char * call_id , int P_pollset_indx, bool ipv6 = false);
230
311
 
231
312
call * add_call(char * call_id , bool ipv6 = false);
232
313
 
233
314
call * add_call(bool ipv6 = false);
234
315
call * get_call(char *);
235
316
void   delete_call(char *);
236
 
 
 
317
void   delete_calls(void);
 
318
 
 
319
void add_running_call(call *call);
 
320
bool remove_running_call(call *call);
 
321
int expire_paused_calls();
 
322
int paused_calls_count();
 
323
void remove_paused_call(call *call);
 
324
 
 
325
#endif