The rule is pretty simple, always use setgid() before setuid().
Reported-by: Jan Pazdziora <jpazdziora@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Make the code avoid divided by zero. This can happen when file has content
but is zero in size. Such files can be found from procfs, possibly some
other pseudo-filesystems. To reproduce the issue run the following.
$ more /proc/crypto
...
Floating point exception (core dumped)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Currently ARROW_DOWN and PAGE_DOWN is bound to command 's' (skip lines).
But this behaviour is not what the user expects, since at least one line
is always missing! Furthermore at the end of the file there is typically
this skipping lines message, if the remainder does not fit in a
complete screen. This conflicts also with e.g. less and man PAGE_DOWN
behaviour. The 'natural' behaviour is binding to
more_kc_jump_lines_per_screen.
If more is extended to also jump only a specific number of lines forward,
this would be even a better binding for ARROW_DOWN.
Before this change the error message about directory was not informative,
and a little bit out of place.
$ touch empty ; ./more ./empty /
::::::::::::::
./empty
::::::::::::::
magic failed: cannot read fd 4 (Is a directory)
::::::::::::::
/
::::::::::::::
After the change messaging is reverted back to what it used to be.
$ ./more ./empty /
::::::::::::::
./empty
::::::::::::::
*** /: directory ***
And while on it lets remove repeated fstat() call.
Fixes: 09070e1a65
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
My earlier change that took libmagic in use to identify mime-type of an input
file caused empty files to be marked binary. Before the change empty files
were simply displayed as empty. This change will restore that behavior.
Addresses: 09070e1a65
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Aim was to introduce page and arrow up/down keys to more(1), but that
also required merging colon_command() and more_key_command() functions.
The more_key_commands enum is pointless from computers point of view.
The command identification performed in read_command() inline with
more_key_command() execution -- but that would be hard for humans, and
source code ought to serve both parties.
Reference: https://github.com/karelzak/util-linux/pull/1003
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
As the old commend said: 'This code would best be shared with the file(1)
program or, perhaps, more should not try to be so smart'. Now at configure
time one can choose whether more(1) is sharing code with file(1), or not.
Addresses: http://bugs.debian.org/139205
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Moving backwards has worked fine until reaching start of file. At that
point more printout had one line too much in output causing more seemingly
never to be able to reach the start. That is now fixed, with clean ups to
skip_backwards() making it less confusing.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit also includes fix to how initial skip lines and search are
instructed in the code. Earlier version was pretty close impossible to make
work with getopt_long() and had minor flaw - if both initial skip lines and
search were defined at the same time the skipping did not happen. That is
now corrected.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
When suspending only the more process. Sending signal to process group
makes signal destination unnecessarily vague. After the suspend is over
SIGCONT is expected, and it needs to ensure output terminal settings are
what more needs.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The wait() is now a little more robust by being more tolerate rogue SIGCHLDs
and unblocked signals. The repeated fork() and sleep() is removed, if first
try does not success give up without delay to provide user timely feedback.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
If streams need to be flushed do not try to be clever, just flush all of
them. That lead to finding unnecessary print out in run_shell() that is
removed in this commit.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The sys/ttydefaults.h can be used for CTRL() and rubout that is CERASE. For
alarm it's best to keep things simple and call printf() alarm modifier.
QUIT was not in use, so it is just deleted.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
As a minor robustness improvement use ftello() to find out file position
rather than add and substract from old value.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Use the backspace provided dy terminfo, and if that is not possible use
fallback.
Simplify entering and exiting standard mode. Now when these std_enter and
std_exit variables are initialized correctly they do not need to be checked
quite as complex way as earlier.
Do not call prepare_line_buffer() unnecessarily. The line buffer needs only
to be prepared only at times of more(1) initialization and when terminal
size changes.
Add a function to print various separators, that is better than static
strings.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Earlier main() inline code implemented input files and stdin displaying
separately. With small restructuring this code can be shared.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Return rather than use long 'else' statement. Also unwind some overly
compact variable set and test code, that can be best observed how
underlining settings are now handled.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Currently open file is needed a bit here and there. Move it to control
structure to avoid passing it around. This also makes fixing memory leak at
more_exit() very easy.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This change also removes a ghost prompt that was left in place when printing
help. When looking old commits the output fluke has been around at least
since util-linux v2.2.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Replacing long 'else' with 'continue' allows dropping one level of
indentation. Main aim is to improve code readability by reducing
complexity one needs to keep track while looking the code.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Pagers are not expected to have setuid or setgid bits, but assuming such
mistake has taken place try to avoid privilege escalation.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This change has three possitive effects: Avoid expansion code when it is
not needed. Stop wasting memory from stack for something rarely needed.
When command buffer is needed stop limiting it's size artificially.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
From man siglongjmp(3) 'longjmp() and siglongjmp() make programs hard to
understand and maintain. If possible, an alternative should be used.' That
manual page remark summarizes quite well why more(1) needs to move away from
jumping around.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Try to make variable names to tell what they do. Earlier names have been in
more(1) since the command was first wrote, and it looks like coding
practices has changed since late 70's.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
One can only assume someone tried to make more(1) to run quicker. More up
to date assumption is that compilers are fully capable optimizing binaries
without these sort of hints.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The curs_terminfo(3X) defines putp() as tputs(str, 1, putchar), so all of
these five functions can be replaced with putp().
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Removal of STOP requires explanation. Looking unix-history-repo getline()
function in first BSD-3 version could return STOP. By next tag BSD-4 the
return STOP had disappeared. If I read this correctly that was a partial
removal, and second part has waited to be completed since 1980-11-16 when
BSD-4 was released.
Reference: https://github.com/dspinellis/unix-history-repo/blob/BSD-3-Snapshot-Development/usr/src/cmd/more.c#L501
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Inlining code using preprocessor function like macros is bad for
readability, and prone to errors. Besides this is a pager, who cares if
code is few milliseconds slower.
Requestee-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This is rather big change, but that is the only way to do this sort job. To
keep this change relatively understandable only moves global variables to a
state structure.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Earlier commit moved lots of functions to work without declarations, but to
be able to get rid of global variables few more moves is needed.
Reference: a8f98304e6
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Group include, defines and such together, and move items inbetween functions
on top of the source file so that everything can be seen easily.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
changed in include/c.h and applied via sed:
sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Now we are always using the same text also for commands
which had still hardcoded descriptions or where we can't
use the standard print_usage_help_options macro.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>