Skip to content

Conversation

@domob1812
Copy link
Contributor

Univalue's parsing of \u escape sequences did not handle NUL characters correctly. They were, effectively, dropped. The extended test-case fails with the old code, and is fixed with this patch.

domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Jun 10, 2015
Currently, the rest.py test fails due to a bug in Univalue with NUL
characters.  This will, hopefully, be fixed upstream in Bitcoin soon.
See my patch:

  bitcoin/bitcoin#6266

Conflicts:
	contrib/gitian-descriptors/gitian-linux.yml
	src/init.cpp
	src/rpcrawtransaction.cpp
	src/rpcserver.cpp
	src/rpcserver.h
	src/test/Checkpoints_tests.cpp
	src/wallet/rpcwallet.cpp
@laanwj
Copy link
Member

laanwj commented Jun 10, 2015

Thanks for thinking about NUL characters, they're a pet peeve of mine.
utACK

@jgarzik
Copy link
Contributor

jgarzik commented Jun 10, 2015

Concept ACK - IMO this needs a really close review to ensure you don't overflow e.g. the buf that shrank from 4 to 3

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This absolutely needs review, but the changes look very sane to me. The buffer size is decreased from 4 to 3 because the last slot was only there to hold a terminating NUL character. This is no longer necessary because the new code counts characters. If this has an overflow bug, it was already there.

I wonder one thing though: could we push_back the characters into valStr directly instead of the intermediate buf? This would avoid any overflow risk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly that was my rationale. The buffer will only ever be accessed in the iterator range [buf, last), and last itself is incremented at most three times.

However, I like your suggestion of using push_back directly! I think that makes sense and will rewrite the code accordingly.

Univalue's parsing of \u escape sequences did not handle NUL characters
correctly.  They were, effectively, dropped.  The extended test-case
fails with the old code, and is fixed with this patch.
@domob1812
Copy link
Contributor Author

I've changed the patch to directly push the characters onto the result instead of using the temporary buffer. This should be cleaner and less prone to potential overflow bugs.

@laanwj
Copy link
Member

laanwj commented Jun 11, 2015

Thanks. re-utACK

@jgarzik
Copy link
Contributor

jgarzik commented Jun 11, 2015

ACK

@jonasschnelli
Copy link
Contributor

Tested & reviewed ACK

@laanwj laanwj merged commit 0cc7b23 into bitcoin:master Jun 12, 2015
laanwj added a commit that referenced this pull request Jun 12, 2015
0cc7b23 Fix univalue handling of \u0000 characters. (Daniel Kraft)
@domob1812 domob1812 deleted the fix-univalue-nul branch June 12, 2015 12:05
@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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants