Skip to content

cosash: Ensure we always inject trailing newline into commands#3127

Merged
jlebon merged 1 commit intocoreos:mainfrom
cgwalters:cosash-newline
Oct 20, 2022
Merged

cosash: Ensure we always inject trailing newline into commands#3127
jlebon merged 1 commit intocoreos:mainfrom
cgwalters:cosash-newline

Conversation

@cgwalters
Copy link
Copy Markdown
Member

The HasPrivileges() API would hang forever because it didn't have a trailing newline in the command emitted. This took me some time to figure out. Let's fix this by auto-injecting a trailing newline automatically to entirely avoid the problem.

The `HasPrivileges()` API would hang forever because it didn't
have a trailing newline in the command emitted.  This took
me some time to figure out.  Let's fix this by auto-injecting
a trailing newline automatically to entirely avoid the problem.
@jlebon jlebon merged commit aeaa1d4 into coreos:main Oct 20, 2022
@cgwalters
Copy link
Copy Markdown
Member Author

A side note, I discovered while using strace on this that bash does 1 byte length reads on stdin...the inefficiency in this in a post-spectre world is high. Of course what we're doing here isn't high performance...

$ strace -f -e read bash -c "echo 'echo hello' | bash"
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\227\2\0\0\0\0\0"..., 832) = 832
read(3, "# Locale name alias data base.\n#"..., 4096) = 2998
read(3, "", 4096)                       = 0
strace: Process 3410022 attached
strace: Process 3410023 attached
[pid 3410022] +++ exited with 0 +++
[pid 3410023] read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
[pid 3410023] read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\227\2\0\0\0\0\0"..., 832) = 832
[pid 3410023] read(3, "# Locale name alias data base.\n#"..., 4096) = 2998
[pid 3410023] read(3, "", 4096)         = 0
[pid 3410023] read(0, "e", 1)           = 1
[pid 3410023] read(0, "c", 1)           = 1
[pid 3410023] read(0, "h", 1)           = 1
[pid 3410023] read(0, "o", 1)           = 1
[pid 3410023] read(0, " ", 1)           = 1
[pid 3410023] read(0, "h", 1)           = 1
[pid 3410023] read(0, "e", 1)           = 1
[pid 3410023] read(0, "l", 1)           = 1
[pid 3410023] read(0, "l", 1)           = 1
[pid 3410023] read(0, "o", 1)           = 1
[pid 3410023] read(0, "\n", 1)          = 1
hello
[pid 3410023] read(0, "", 1)            = 0
[pid 3410023] +++ exited with 0 +++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants