jvandal / modwsgi

Automatically exported from code.google.com/p/modwsgi
0 stars 0 forks source link

sys.stderr/wsgi.errors truncate data when contains embedded null #124

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

The streams sys.stderr and wsgi.errors wrap the Apache functions for logging to 
the Apache 
error log. Those functions though only accept data up to an embedded null 
character. Ie., will 
only accept normal C strings and not arbitrary data of a specific length.

This means that when string written containing embedded null, any data 
following embedded 
null up to following newline will be lost.

Rather than use Apache functions for logging to the Apache error log, should 
directly grab 
error_log file reference from server_rec and write to it. Will though need to 
prepend each line 
with same style of header as Apache functions for logging use. In other words, 
just need to allow 
for writing data based on length rather than null terminate C strings.

If logging data for debug purposes, calling repr() on data before writing would 
be a prudent 
thing to do so that avoid this problem and also avoid any other issues which 
magic control 
characters in error log files.

Original issue reported on code.google.com by Graham.Dumpleton@gmail.com on 20 Jan 2009 at 12:58

GoogleCodeExporter commented 8 years ago
Fixed in revision 1178 of mod_wsgi 3.0 (trunk).

Note that there is a still a limitation due to logging via Apache error log 
functions, namely that a line will be 
truncated at 8192 characters inclusive of timestamp prefix.

The Apache error log functions are used so that messages can be processed 
correctly by Apache modules 
which register to see them. Also required where Apache configured to fallback 
to using syslog for logging.

If not using syslog and want logging to go through untouched, then use:

  import sys
  sys.__stderr__.write(rawmessage)
  sys.__stderr__.flush()

This will be logged but with not timestamp prefix. A flush is required for data 
to appear in logs immediately. 
If no flush done, not guaranteed that message will end up in log file.

Original comment by Graham.Dumpleton@gmail.com on 6 Feb 2009 at 7:38

GoogleCodeExporter commented 8 years ago
Going to create a separate issue for the truncation at about 8192 characters in 
a line.

Original comment by Graham.Dumpleton@gmail.com on 6 Feb 2009 at 1:53

GoogleCodeExporter commented 8 years ago
Truncation around 8192 bytes covered by issue:

  http://code.google.com/p/modwsgi/issues/detail?id=130

Original comment by Graham.Dumpleton@gmail.com on 6 Feb 2009 at 2:19

GoogleCodeExporter commented 8 years ago
Reverted changes in revision 1270 of trunk for mod_wsgi 3.0.

The fix had been to treat a NULL as a newline. But seen as better at this point 
to leave behaviour as it was.

Returning it to original behaviours makes it consistent with how FASTCGI 
solutions for Apache work.

Original comment by Graham.Dumpleton@gmail.com on 1 Apr 2009 at 9:59

GoogleCodeExporter commented 8 years ago
Closing as no ready solution to issue.

Original comment by Graham.Dumpleton@gmail.com on 12 Nov 2014 at 10:53

GoogleCodeExporter commented 8 years ago
Closing as no ready solution to issue.

Original comment by Graham.Dumpleton@gmail.com on 12 Nov 2014 at 10:53