Module: kamailio
Branch: master
Commit: 02fc919e4f177cc3ab9c5d53eb9ea2019c572bd9
URL:
https://github.com/kamailio/kamailio/commit/02fc919e4f177cc3ab9c5d53eb9ea20…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-12-03T14:07:34+01:00
pv: use static buffer for ctime_r() output and check its return
- fixed $TF output, regression introduced when switching to thread safe
time function
---
Modified: src/modules/pv/pv_time.c
---
Diff:
https://github.com/kamailio/kamailio/commit/02fc919e4f177cc3ab9c5d53eb9ea20…
Patch:
https://github.com/kamailio/kamailio/commit/02fc919e4f177cc3ab9c5d53eb9ea20…
---
diff --git a/src/modules/pv/pv_time.c b/src/modules/pv/pv_time.c
index 87b62b71e9..4a9cc14dd1 100644
--- a/src/modules/pv/pv_time.c
+++ b/src/modules/pv/pv_time.c
@@ -246,12 +246,16 @@ int pv_get_timenowf(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
str s;
- char t_buf[26] = {0};
+ static char t_buf[26] = {0};
time_t t;
t = time(NULL);
s.s = ctime_r(&t, t_buf);
+ if(s.s == NULL) {
+ return pv_get_null(msg, param, res);
+ }
+ s.s = t_buf;
s.len = strlen(s.s)-1;
return pv_get_strintval(msg, param, res, &s, (int)t);
}
@@ -271,7 +275,7 @@ int pv_get_timef(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
str s;
- char t_buf[26] = {0};
+ static char t_buf[26] = {0};
if(msg==NULL)
return -1;
@@ -279,6 +283,10 @@ int pv_get_timef(struct sip_msg *msg, pv_param_t *param,
msg_set_time(msg);
s.s = ctime_r(&msg->tval.tv_sec, t_buf);
+ if(s.s == NULL) {
+ return pv_get_null(msg, param, res);
+ }
+ s.s = t_buf;
s.len = strlen(s.s)-1;
return pv_get_strintval(msg, param, res, &s, (int)msg->tval.tv_sec);
}