Browse code

pv: use static buffer for ctime_r() output and check its return

- fixed $TF output, regression introduced when switching to thread safe
time function

Daniel-Constantin Mierla authored on 03/12/2020 13:07:34
Showing 1 changed files
... ...
@@ -246,12 +246,16 @@ int pv_get_timenowf(struct sip_msg *msg, pv_param_t *param,
246 246
 		pv_value_t *res)
247 247
 {
248 248
 	str s;
249
-	char t_buf[26] = {0};
249
+	static char t_buf[26] = {0};
250 250
 	time_t t;
251 251
 
252 252
 	t = time(NULL);
253 253
 
254 254
 	s.s = ctime_r(&t, t_buf);
255
+	if(s.s == NULL) {
256
+		return pv_get_null(msg, param, res);
257
+	}
258
+	s.s = t_buf;
255 259
 	s.len = strlen(s.s)-1;
256 260
 	return pv_get_strintval(msg, param, res, &s, (int)t);
257 261
 }
... ...
@@ -271,7 +275,7 @@ int pv_get_timef(struct sip_msg *msg, pv_param_t *param,
271 275
 		pv_value_t *res)
272 276
 {
273 277
 	str s;
274
-	char t_buf[26] = {0};
278
+	static char t_buf[26] = {0};
275 279
 
276 280
 	if(msg==NULL)
277 281
 		return -1;
... ...
@@ -279,6 +283,10 @@ int pv_get_timef(struct sip_msg *msg, pv_param_t *param,
279 283
 	msg_set_time(msg);
280 284
 
281 285
 	s.s = ctime_r(&msg->tval.tv_sec, t_buf);
286
+	if(s.s == NULL) {
287
+		return pv_get_null(msg, param, res);
288
+	}
289
+	s.s = t_buf;
282 290
 	s.len = strlen(s.s)-1;
283 291
 	return pv_get_strintval(msg, param, res, &s, (int)msg->tval.tv_sec);
284 292
 }