[Asterisk-Dev] Patch to avoid writing to constant strings in pbx.c
Luke Howard
lukeh at PADL.COM
Sun Mar 23 01:18:39 MST 2003
pbx_substitute_variables_temp() would try to write to a constant string
in cases such as a remote endpoint having no caller ID and an offset
being defined.
In the following example, if CALLERIDNUM was NULL, it would be set to
"", and pbx_substitute_variables_temp() would try and assign a value to
the constant string "".
[remote]
exten => _95555XXX,1,SetCallerID(+61${CALLERIDNUM:1})
exten => _95555XXX,2,Goto(default,${EXTEN:5},1)
One workaround would be to compile with -fwriteable-strings, but the
attached patch fixes this properly (at least for the said function).
-- Luke
-------------- next part --------------
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.1.1.12
diff -u -r1.1.1.12 pbx.c
--- pbx.c 18 Mar 2003 19:55:35 -0000 1.1.1.12
+++ pbx.c 23 Mar 2003 08:20:48 -0000
@@ -718,21 +718,26 @@
if (num) {
ast_shrink_phone_number(num);
*cp4 = num;
- } else
- *cp4 = "";
+ } else {
+ cid[0] = '\0';
+ *cp4 = cid;
+ }
} else if (!strcmp(cp3, "CALLERIDNAME")) {
char cid[256] = "";
if (c->callerid)
strncpy(cid, c->callerid, sizeof(cid) - 1);
ast_callerid_parse(cid, &name, &num);
- if (name)
+ if (name) {
*cp4 = name;
- else
- *cp4 = "";
+ } else {
+ cid[0] = '\0';
+ *cp4 = cid;
+ }
} else if (!strcmp(cp3, "CALLERID")) {
+ char cid[1] = "";
*cp4 = c->callerid;
if (!(*cp4))
- *cp4 = "";
+ *cp4 = cid;
} else if (!strcmp(cp3, "EXTEN")) {
*cp4 = c->exten;
} else if (!strncmp(cp3, "EXTEN-", strlen("EXTEN-")) &&
@@ -754,9 +759,10 @@
*cp4 = c->exten + offset;
#endif
} else if (!strcmp(cp3, "RDNIS")) {
+ char rdins[1] = "";
*cp4 = c->rdnis;
if (!(*cp4))
- *cp4 = "";
+ *cp4 = rdins;
} else if (!strcmp(cp3, "CONTEXT")) {
*cp4 = c->context;
} else if (!strcmp(cp3, "PRIORITY")) {
-------------- next part --------------
--
Luke Howard | PADL Software Pty Ltd | www.padl.com
More information about the asterisk-dev
mailing list