Browse code

xprint: use ctime_r() for a safer multi-thread usage

> The reentrant version ctime_r() does the same, but stores
> the string in a user-supplied buffer which should have
> room for at least 26 bytes.

Victor Seva authored on 12/05/2020 12:38:43
Showing 1 changed files
... ...
@@ -164,7 +164,7 @@ static int xl_get_times(struct sip_msg *msg, str *res, str *hp, int hi, int hf)
164 164
 }
165 165
 static int xl_get_timef(struct sip_msg *msg, str *res, str *hp, int hi, int hf)
166 166
 {
167
-	char *ch = NULL;
167
+	char ch[26] = {0};
168 168
 
169 169
 	if(msg==NULL || res==NULL)
170 170
 		return -1;
... ...
@@ -174,7 +174,7 @@ static int xl_get_timef(struct sip_msg *msg, str *res, str *hp, int hi, int hf)
174 174
 		msg_id = msg->id;
175 175
 	}
176 176
 
177
-	ch = ctime(&msg_tm);
177
+	ctime_r(&msg_tm, ch);
178 178
 
179 179
 	res->s = ch;
180 180
 	res->len = strlen(ch)-1;