Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1510002 - Ensure that the command input (stdin) eating behaviour of Default log_input is documented
Summary: Ensure that the command input (stdin) eating behaviour of Default log_input i...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: sudo
Version: 7.4
Hardware: x86_64
OS: Linux
medium
high
Target Milestone: rc
: ---
Assignee: Radovan Sroka
QA Contact: Dalibor Pospíšil
URL:
Whiteboard:
Depends On: 1547974
Blocks: 1477664
TreeView+ depends on / blocked
 
Reported: 2017-11-06 14:32 UTC by Dalibor Pospíšil
Modified: 2018-10-30 11:09 UTC (History)
5 users (show)

Fixed In Version: sudo-1.8.23-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-10-30 11:09:01 UTC


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2018:3199 None None None 2018-10-30 11:09:46 UTC
Red Hat Bugzilla 1454571 None CLOSED Sudo, with I/O Logging log_output option enabled, truncate output in case of cycle over standard input 2019-04-16 08:59:13 UTC

Internal Links: 1454571

Description Dalibor Pospíšil 2017-11-06 14:32:56 UTC
Description of problem:

There's an issue with sudo, that is truncating output in stdout file descriptor upon log_input (io logging) option usage.

Version-Release number of selected component (if applicable):

Affected and tested versions:
sudo-1.8.19p2-12.el7
sudo-1.8.19p2-11.el7

How reproducible:
Always

Steps to Reproduce:

Just run this script (also attacched):

#!/bin/bash
printf "usqpsinfra1\nusqpsinfra2\n" | while read node; do sudo echo $node; done

Actual results:
only usqpsinfra1 is outputted:

$ bash -x test
+ read node
+ printf 'usqpsinfra1\nusqpsinfra2\n'
+ sudo echo usqpsinfra1
usqpsinfra1
+ read node
$

Expected results:
$ bash -x test
+ read node
+ printf 'usqpsinfra1\nusqpsinfra2\n'
+ sudo echo usqpsinfra1
usqpsinfra1
+ read node
+ sudo echo usqpsinfra2
usqpsinfra2
+ read node
$

Comment 2 Radovan Sroka 2018-06-20 10:53:20 UTC
Hi guys,

after some investigation we can say that this is not a bug.

The problem is that "sudo" and "read" stdin is inherited from while. "read" reads 1st line from stdin and then sudo is called and io-logging plugin consumes the rest of the stdin. stdin content is not supposed to be for "sudo" but sudo has no idea whether stdin is shared or not.

It is much better to use some of the following work arounds to avoid confusion.

printf "a\nb\nc\n" | sudo bash -c 'while read a; do echo $a; done'
printf "a\nb\nc\n" | while read a; do sudo echo $a 0<&- ; done
printf "a\nb\nc\n" | while read a; do : | sudo echo $a ; done

It is also documented in manual (man sudoers).

"Anything sent to the standard input will be consumed, regardless of whether or not the command run via sudo is actually reading the standard input. This may have unexpected results when using sudo in a shell script that expects to process the standard input." ---> log_input documentation

https://www.sudo.ws/man/1.8.22/sudoers.man.html

Comment 3 Dalibor Pospíšil 2018-06-20 18:56:37 UTC
So do I understand correctly, that sudo eats all the input up, except for the first line, before the read gets in line?

Comment 4 Radovan Sroka 2018-06-21 07:53:51 UTC
(In reply to Dalibor Pospíšil from comment #3)
> So do I understand correctly, that sudo eats all the input up, except for
> the first line, before the read gets in line?

It should be like that:

printf "usqpsinfra1\nusqpsinfra2\n" | while read node; do sudo echo $node; done

$ bash -x test
+ read node    <--- read was forked from while
+ printf 'usqpsinfra1\nusqpsinfra2\n' <--- send data to while's stdin
+                         <--- read eats the first line
+ sudo echo usqpsinfra1   <--- sudo was forked from while with first line as argument and it eats the rest of stdin
usqpsinfra1    <--- stdout of sudo
+ read node    <--- read has no input so loop is over
$

Comment 9 errata-xmlrpc 2018-10-30 11:09:01 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:3199


Note You need to log in before you can comment on or make changes to this bug.