Bug #6726


Syslog crashes when the special %m tag (of syslog(3)) is present in the message

Added by ameuret (Arnaud MEURET) almost 10 years ago. Updated almost 3 years ago.

Target version:
ruby -v:
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


The %m special escape sequence supported by the syslog(3) system call is claimed by the Ruby doc to be supported by the ::Syslog Ruby class. However the implementation of ::Syslog in ext/syslog/syslog.c:49 ( calls rb_f_sprintf() which does not tolerate the presence of %m in the format string.

A quick dump of a pry session demonstrating the crash:

[1] pry(main)> require 'syslog'
=> true
[2] pry(main)>
=> <#Syslog: opened=true, ident="pry", options=3, facility=8, mask=255>
[3] pry(main)> "Hi !%m"
ArgumentError: malformed format string - %m
from (pry):3:in `info

Updated by nobu (Nobuyoshi Nakada) almost 10 years ago

I think the following document introduced at #4149 is wrong, since ((|errno|)) is C-level interface and not available in Ruby-level, and may not be preserved across method calls.

%m is replaced with the error message string that would be returned by strerror(errno).

So possible fixes would be:
(1) fix document, by removing above sentence.
(2) replace %m with other thing, $! for example.

The latter sounds useful, but will be larger change.

Actions #2

Updated by drbrain (Eric Hodel) almost 10 years ago

  • Category set to ext
  • Assignee set to knu (Akinori MUSHA)
  • Priority changed from 3 to Normal

Updated by kosaki (Motohiro KOSAKI) almost 10 years ago

I recommend to just remove the doc. If anyone want pretty print $!, It should be used original and unique format string, not %m.

Actions #4

Updated by mame (Yusuke Endoh) almost 10 years ago

  • Status changed from Open to Assigned
Actions #5

Updated by jeremyevans (Jeremy Evans) almost 3 years ago

  • Status changed from Assigned to Closed

Applied in changeset git|2b6441196ef32d93c7898764610a913f54f8bc32.

Remove documentation of %m in Syslog

Fixes [Bug #6726]


Also available in: Atom PDF