discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
* File type detection
@ 2015-09-01  1:43 Warren Block
  2015-09-02 15:33 ` Ingo Schwarze
  0 siblings, 1 reply; 2+ messages in thread
From: Warren Block @ 2015-09-01  1:43 UTC (permalink / raw)
  To: discuss

Just tonight, it was pointed out on IRC that 'man /bin/sh' on FreeBSD 
failed spectacularly.  Unfortunately, 'mandoc /bin/sh' also fails, 
although not as badly.

Is it feasible to use file(1) to check a file's type before displaying 
it?  Or maybe to incorporate some of those or similar tests directly 
into mandoc?
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: File type detection
  2015-09-01  1:43 File type detection Warren Block
@ 2015-09-02 15:33 ` Ingo Schwarze
  0 siblings, 0 replies; 2+ messages in thread
From: Ingo Schwarze @ 2015-09-02 15:33 UTC (permalink / raw)
  To: discuss; +Cc: Warren Block

Hi Warren,

Warren Block wrote on Mon, Aug 31, 2015 at 07:43:12PM -0600:

> Just tonight, it was pointed out on IRC that 'man /bin/sh' on FreeBSD
> failed spectacularly.

In which way exactly?  On OpenBSD, i see this:

  schwarze@isnote $ man /bin/sh
  man: No entry for /bin/sh in the manual.

That seems like the correct answer to me because indeed,
there is no manual page named '/bin/sh', and the man(1)
manual says:

  man [...] name ...

  The man utility displays the manual pages entitled _name_.

> Unfortunately, 'mandoc /bin/sh' also fails, although not as
> badly.

In which way exactly?  On OpenBSD, i see this:

  schwarze@isnote $ mandoc /bin/sh
  ()                                                          ()

  ?ELF???????????????????? 6??4???Oe??????4? ? ?(?????????4???4???4??? ???
  ???????????????????????????b??b???????????????p????? ???
  [...]

That seems correct behaviour, too.  The mandoc(1) manual says:

  mandoc [...] [file ...]

  The mandoc utility formats UNIX manual pages for display.
  By default, mandoc reads mdoc(7) or man(7) text from stdin, implying
  -mandoc, and produces -T locale output.
  [...]
  Input Formats
  [...]
  A third option, -mandoc, which is also the default, determines encoding
  on-the-fly: if the first non-comment macro is `Dd' or `Dt', the mdoc(7)
  parser is used; otherwise, the man(7) parser is used.

So, the binary is interpreted as man(7) code, as it should,
and invalid characters are replaced with question marks.

> Is it feasible to use file(1) to check a file's type before
> displaying it?

No.  Mandoc is a moderately security-sensitive program because root
may run it.  Complexity should be avoided.  Besides, on most systems,
the implementation of file(1) is very low-quality, insecure, and should
never be run by root.

> Or maybe to incorporate some of those or similar tests directly
> into mandoc?

No.  Too much complexity.  What's wrong with the current behaviour?
I see no need to do anything special about blatant abuse like "mandoc
/bin/sh" that will only very rarely happen in practice.

Yours,
  Ingo
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-09-02 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-01  1:43 File type detection Warren Block
2015-09-02 15:33 ` Ingo Schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).