Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 9761

Summary: `man -k` seg faults if its argument contains multiple words
Product: Gentoo Linux Reporter: Ivan Raikov <raikov>
Component: [OLD] Core systemAssignee: Martin Schlemmer (RETIRED) <azarah>
Status: RESOLVED FIXED    
Severity: normal    
Priority: High    
Version: 1.3   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: man-1.5k-util_c-segfault.patch

Description Ivan Raikov 2002-10-27 09:12:21 UTC
$ man -k blah       
blah: nothing appropriate

$ man -k "blah blah"
sh: unsafe: command not found
Error executing formatting or display command.
System command unsafe exited with status 127.
Segmentation fault

$ man --version
man, version 1.5k
Comment 1 Martin Schlemmer (RETIRED) gentoo-dev 2002-12-26 12:55:57 UTC
Created attachment 6746 [details, diff]
man-1.5k-util_c-segfault.patch

  26 Dec 2002; Martin Schlemmer <azarah@gentoo.org> man-1.5k.ebuild,
						    man-1.5k-r1.ebuild :

  Bugfixes:
  - Add man-1.5k-util_c-segfault.patch to fix a crash when calling man
    with:  man -k "foo bar" (bug #9761).
Comment 2 Martin Schlemmer (RETIRED) gentoo-dev 2002-12-26 12:58:58 UTC
The reason for this is that my_xsprintf() in util.c passes
NOT_SAFE as the result if the string is not shell safe.
When do_appros() (or whatever) then calls 'free(command)',
free() tries to free a constant, and segfault.

The attached solution are not eligant, but works without
breaking the API.  Basically we redefine NOT_SAFE as a
message that we want to display, prepended with 'echo'.
When the command is then executed, our message are displayed,
and not the the line containing:
  
  sh: line 1: unsafe: command not found

Further more, we do not return NOT_SAFE, but rather a string
that we malloc, and then fill with the contents of NOT_SAFE,
which will solve us trying to free a constant.

Alternatively it is possible to redefine what is "shell safe",
but that will me a much more comprehensive fix ...

-----
$ man -k "blah blah"
Cannot run command, as it is not shell safe!
Check that you do not quote search strings, etc.
Comment 3 Martin Schlemmer (RETIRED) gentoo-dev 2002-12-29 11:42:39 UTC
Fixed.