[Live-devel] dateHeader() obeys locale, but shouldn't

Lauri Nurmi lauri.nurmi at obseron.com
Wed Feb 28 02:59:44 PST 2024


Hello,

The “dateHeader()” function in RTSPCommon.cpp obeys the current locale, 
while it really shouldn't. As a result, Date: headers may be shown in 
localized format, which is undesirable and probably not allowed by the 
RTSP specification.

To reproduce:

Add “#include <locale.h>” and add “setlocale(LC_ALL, "");” to the very 
beginning of “main()” in live555MediaServer.cpp. Then run the server 
using a locale that exists on the system, for example:

LC_ALL=fi_FI.UTF-8 ./live555MediaServer

Now, connecting to the server with telnet and entering some invalid line 
results in the following reply:

RTSP/1.0 400 Bad Request
Date: Ke, Hel 28 2024 09:56:24 GMT
Allow: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, 
SET_PARAMETER

If using e.g. “ja_JP.UTF-8”, the date is even more noticeably localized:

Date: 水,  2 28 2024 09:57:42 GMT

Proposed solution: Implement dateHeader() without using strftime():

--- a/live/liveMedia/RTSPCommon.cpp
+++ b/live/liveMedia/RTSPCommon.cpp
@@ -365,7 +365,13 @@ char const* dateHeader() {
      time_tm = tm();
    }
  #endif
-  strftime(buf, sizeof buf, "Date: %a, %b %d %Y %H:%M:%S GMT\r\n", 
&time_tm);
+  static const char *day[] = { "Sun", "Mon", "Tue", "Wed", "Thu", 
"Fri", "Sat" },
+                    *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+                                 "Jul", "Aug", "Sep", "Oct", "Nov", 
"Dec" };
+  snprintf(buf, sizeof buf, "Date: %s, %s %02d %04d %02d:%02d:%02d 
GMT\r\n",
+          day[time_tm.tm_wday], month[time_tm.tm_mon], time_tm.tm_mday,
+          1900 + time_tm.tm_year,
+          time_tm.tm_hour, time_tm.tm_min, time_tm.tm_sec);
  #else
    // WinCE apparently doesn't have "time()", "strftime()", or "gmtime()",
    // so generate the "Date:" header a different, WinCE-specific way.

-- 
(Mr) Lauri Nurmi
Software Engineer, M.Sc. (Tech.)
www.obseron.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20240228/3c9279c8/attachment.htm>


More information about the live-devel mailing list