Skip to content

Conversation

@gmaxwell
Copy link
Contributor

@gmaxwell gmaxwell commented Feb 8, 2015

Normally bitcoin core does not display any network originated strings without
sanitizing or hex encoding. This wasn't done for strcommand in many places.

This could be used to play havoc with a terminal displaying the logs,
especially with printtoconsole in use.

Thanks to Evil-Knievel for reporting this issue.

@laanwj laanwj added the Bug label Feb 8, 2015
@laanwj
Copy link
Member

laanwj commented Feb 8, 2015

utACK

@jgarzik
Copy link
Contributor

jgarzik commented Feb 8, 2015

ut ACK

@paveljanik
Copy link
Contributor

ACK

@fanquake
Copy link
Member

fanquake commented Feb 8, 2015

utACK

@laanwj
Copy link
Member

laanwj commented Feb 8, 2015

@paveljanik
Copy link
Contributor

Hmm, can't we call sanitize on the command string directly on input instead later on every LogPrint?

@jonasschnelli
Copy link
Contributor

Somehow related: #5492

@laanwj
Copy link
Member

laanwj commented Feb 8, 2015

The problem here is the output, hence the point is to sanitize on output, not the input. Operations on valid input may still result in output strings that are 'dangerous'. Filtering out the characters on input would result in the counter-intuitive behavior that "get\x1bblock"is an alias for "getblock" (for another example of input and output sanitization being confused only look as far as PHP's 'magic quotes' disaster, which has corrupted texts with extra \ and didn't solve the underlying SQL injection at all).

(Prematurely rejecting commands with control or non-ASCII characters would of course be more reasonable, as there are none of those that we handle anyway)

But in any case, we'd like to minimize code impact outside of immediate logging/debugging code. E.g. @gmaxwell and I have talked about changing LogPrintStr to replace with ' ' any control characters except a '\n' at the end of the string. This would solve this problem thoroughly without any potential side-impact on the code.

Edit: and this specific code change should go in as well, it'd just be a last ditch catch-all.

Normally bitcoin core does not display any network originated strings without
 sanitizing or hex encoding.  This wasn't done for strcommand in many places.

This could be used to play havoc with a terminal displaying the logs,
 especially with printtoconsole in use.

Thanks to Evil-Knievel for reporting this issue.
@gmaxwell
Copy link
Contributor Author

gmaxwell commented Feb 8, 2015

@laanwj good catch; I saw the one at 1974 but because it was outgoing I didn't hit it. Since it caught your attention to, I'll just add it; better than people in the future spending time thinking about it being okay or not.

@laanwj laanwj merged commit 28d4cff into bitcoin:master Feb 9, 2015
laanwj added a commit that referenced this pull request Feb 9, 2015
28d4cff Sanitize command strings before logging them. (Gregory Maxwell)
gmaxwell added a commit that referenced this pull request Feb 13, 2015
Normally bitcoin core does not display any network originated strings without
 sanitizing or hex encoding.  This wasn't done for strcommand in many places.

This could be used to play havoc with a terminal displaying the logs,
 especially with printtoconsole in use.

Thanks to Evil-Knievel for reporting this issue.

Conflicts:
	src/main.cpp
	src/net.cpp
	src/rpcserver.cpp

Rebased-From: 28d4cff
Github-Pull: #5770
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants