Skip to content

Commit 0147baa

Browse files
committed
Convert _str() from inline to a macro and make it return
(const str *), not (str *). This is to limit potential damage from its (mis)use in non-testing modules code by first making its value stored locally at point of use (which should allow compiler to throw it away when used properly) and also provide at least some protection from any function from messing with its fields. Fix any fallout where str * has been passed around.
1 parent d85d0b5 commit 0147baa

File tree

7 files changed

+20
-19
lines changed

7 files changed

+20
-19
lines changed

modules/dialog/dlg_handlers.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2707,8 +2707,8 @@ int dlg_validate_dialog( struct sip_msg* req, struct dlg_cell *dlg)
27072707
return 0;
27082708
}
27092709

2710-
int terminate_dlg(str *callid, unsigned int h_entry, unsigned int h_id,
2711-
str *reason)
2710+
int terminate_dlg(const str *callid, unsigned int h_entry, unsigned int h_id,
2711+
const str *reason)
27122712
{
27132713
struct dlg_cell * dlg = NULL;
27142714
int ret = 0;

modules/dialog/dlg_handlers.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ typedef int (*validate_dialog_f) (struct sip_msg* req, struct dlg_cell *dlg);
101101
typedef int (*fix_route_dialog_f) (struct sip_msg *req,struct dlg_cell *dlg);
102102
/* the dialog is identified by callid if provided,
103103
* otherwise by h_entry and h_id */
104-
typedef int (*terminate_dlg_f)(str *callid, unsigned int h_entry,
105-
unsigned int h_id, str *reason);
104+
typedef int (*terminate_dlg_f)(const str *callid, unsigned int h_entry,
105+
unsigned int h_id, const str *reason);
106106
typedef int (*indialog_reply_f) (struct sip_msg *msg, int statuscode,
107107
void *param);
108108
typedef int (*send_indialog_req_f)(struct dlg_cell *dlg, str *method,
@@ -128,8 +128,8 @@ int dlg_validate_dialog( struct sip_msg* req, struct dlg_cell *dlg);
128128

129129
int fix_route_dialog(struct sip_msg *req,struct dlg_cell *dlg);
130130

131-
int terminate_dlg(str *callid, unsigned int h_entry, unsigned int h_id,
132-
str *reason);
131+
int terminate_dlg(const str *callid, unsigned int h_entry, unsigned int h_id,
132+
const str *reason);
133133

134134
int send_indialog_request(struct dlg_cell *dlg, str *method,
135135
int leg, str *body, str *ct, str *hdrs, indialog_reply_f func,

modules/dialog/dlg_hash.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ struct dlg_cell* get_dlg_by_val(str *attr, str *val)
867867
}
868868

869869

870-
struct dlg_cell* get_dlg_by_callid( str *callid, int active_only)
870+
struct dlg_cell* get_dlg_by_callid(const str *callid, int active_only)
871871
{
872872
struct dlg_cell *dlg;
873873
struct dlg_entry *d_entry;

modules/dialog/dlg_hash.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ struct dlg_cell* get_dlg(str *callid, str *ftag, str *ttag,
397397

398398
struct dlg_cell* get_dlg_by_val(str *attr, str *val);
399399

400-
struct dlg_cell* get_dlg_by_callid( str *callid, int active_only);
400+
struct dlg_cell* get_dlg_by_callid(const str *callid, int active_only);
401401

402402
struct dlg_cell* get_dlg_by_did(str *did, int active_only);
403403

modules/dialog/dlg_load.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
typedef struct dlg_cell *(*get_dlg_f) (void);
3333
typedef str *(*get_dlg_did_f) (struct dlg_cell *dlg);
34-
typedef struct dlg_cell *(*get_dlg_by_callid_f) (str *, int);
34+
typedef struct dlg_cell *(*get_dlg_by_callid_f) (const str *, int);
3535
typedef struct dlg_cell *(*get_dlg_by_did_f) (str *, int);
3636
typedef int (*match_dialog_f) (struct sip_msg *msg, int _seq_match_mode);
3737
typedef int (*get_direction_f) (void);

modules/dialplan/dialplan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ struct module_exports exports= {
172172

173173

174174
/*Inserts table_name/db url into the list of heads*/
175-
static int dp_head_insert(int dp_insert_type, str *content,
175+
static int dp_head_insert(int dp_insert_type, const str *content,
176176
str *partition)
177177
{
178178
#define h_insert(type, url_str, table_str, ins_str ) \

str.h

+10-9
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,17 @@ static inline str *str_cpy(str *dest, const str *src)
9797
/**
9898
* Handy function for writing unit tests which compare str's
9999
*
100-
* WARNING: _only_ use when passing (str *) to _basic_ functions,
101-
* since it is not re-entrant and may cause ugly bugs!
100+
* WARNING: _only_ use when passing (const str *) to _basic_
101+
* functions, since while poiter is stable for the
102+
* lifetime of the application its value is mutable
103+
* and bad code messing it around may cause ugly bugs!
102104
*/
103-
static inline str *_str(const char *s)
104-
{
105-
static str st;
106-
107-
init_str(&st, s);
108-
return &st;
109-
}
105+
#define _str(s) ( \
106+
{ \
107+
static str _st; \
108+
init_str(&_st, s); \
109+
/* return */ (const str *)&_st; \
110+
})
110111

111112
/**
112113
* Initialize private static str_const given the static buffer

0 commit comments

Comments
 (0)