-
Notifications
You must be signed in to change notification settings - Fork 902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple misc cleanups #4227
Simple misc cleanups #4227
Conversation
d060193
to
52b5ee1
Compare
return NULL; | ||
|
||
/* Add one for nul term */ | ||
ret = tal_dup_arr(ctx, char, (const char *)buf, buflen, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should takes be taken into account here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tal_dup_arr takes already...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the string is already null-terminated? Could we end up in a situation where we call utf8_str
multiple times, each time re-allocating it to append the \0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it would. We should probably reject NULs in strings as not UTF-8.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis is complaining about memory in the unit tests, otherwise lgtm
ALGRIND=1 valgrind -q --error-exitcode=7 --track-origins=yes --leak-check=full --show-reachable=yes --errors-for-leak-kinds=all common/test/run-bolt11 > /dev/null
==14956== 52 bytes in 1 blocks are still reachable in loss record 1 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FAC7: main (run-bolt11.c:590)
==14956==
==14956== 52 bytes in 1 blocks are still reachable in loss record 2 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FBD5: main (run-bolt11.c:598)
==14956==
==14956== 52 bytes in 1 blocks are still reachable in loss record 3 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FD6A: main (run-bolt11.c:610)
==14956==
==14956== 53 bytes in 1 blocks are still reachable in loss record 4 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FB4E: main (run-bolt11.c:594)
==14956==
==14956== 53 bytes in 1 blocks are still reachable in loss record 5 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FC5C: main (run-bolt11.c:602)
==14956==
==14956== 53 bytes in 1 blocks are still reachable in loss record 6 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FDF1: main (run-bolt11.c:614)
==14956==
==14956== 54 bytes in 1 blocks are still reachable in loss record 7 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FCE3: main (run-bolt11.c:606)
==14956==
==14956== 54 bytes in 1 blocks are still reachable in loss record 8 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FE78: main (run-bolt11.c:618)
==14956==
==14956== 54 bytes in 1 blocks are still reachable in loss record 9 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FEFF: main (run-bolt11.c:622)
==14956==
==14956== 55 bytes in 1 blocks are still reachable in loss record 10 of 12
==14956== at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x131CD3: allocate (tal.c:250)
==14956== by 0x13226C: tal_alloc_ (tal.c:428)
==14956== by 0x13242D: tal_alloc_arr_ (tal.c:471)
==14956== by 0x1382DC: decode_d (bolt11.c:185)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FF86: main (run-bolt11.c:626)
==14956==
==14956== 80 bytes in 1 blocks are still reachable in loss record 11 of 12
==14956== at 0x4C33D2F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x12EB63: take_ (take.c:23)
==14956== by 0x13835C: decode_d (bolt11.c:189)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FF86: main (run-bolt11.c:626)
==14956==
==14956== 80 bytes in 1 blocks are still reachable in loss record 12 of 12
==14956== at 0x4C33D2F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==14956== by 0x12EBF4: take_ (take.c:37)
==14956== by 0x13835C: decode_d (bolt11.c:189)
==14956== by 0x139C71: bolt11_decode (bolt11.c:728)
==14956== by 0x13FF86: main (run-bolt11.c:626)
==14956==
Makefile:589: recipe for target 'unittest/common/test/run-bolt11' failed
make: *** [unittest/common/test/run-bolt11] Error 7
The command ".travis/build.sh" exited with 2.
cache.2
store build cache
|
||
for (size_t i = 0; i < buflen; i++) { | ||
if (!utf8_decode(&utf8_state, buf[i])) { | ||
need_more = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there no early exit for invalid utf-8? the need_more
flag flipping is a bit unintuitive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utf8_decode is a bit weird:
/*
* Returns false if it needs another character to give results.
* Otherwise returns true, @utf8_state can be reused without initializeation,
* and sets errno:
* 0: success
* EINVAL: bad encoding.
* EFBIG: not a minimal encoding.
* ERANGE: encoding of invalid character.
*/
Signed-off-by: Rusty Russell <[email protected]>
We don't have a problem with them, but callers may; easier to reject bad UTF8 here than let the caller fail when it tries to parse output. Signed-off-by: Rusty Russell <[email protected]>
We already do some sanity checks, add this one. Signed-off-by: Rusty Russell <[email protected]> Changelog-Changed: JSON-RPC: invalid UTF-8 strings now rejected.
There's a 60 second delay in one of the contrib tests, and I just want to run flake8 on my alterations. Signed-off-by: Rusty Russell <[email protected]>
Not really a leak, since we eventually process pending, but still: ``` **BROKEN** gossipd: MEMLEAK: 0x5562fa63bab8 **BROKEN** gossipd: label=wire/peer_exp_wiregen.c:3858:u8[] DEBUG gossipd: backtrace: DEBUG gossipd: ccan/ccan/tal/tal.c:442 (tal_alloc_) DEBUG gossipd: ccan/ccan/tal/tal.c:471 (tal_alloc_arr_) DEBUG gossipd: wire/peer_exp_wiregen.c:3858 (fromwire_channel_announcement) DEBUG gossipd: gossipd/routing.c:1706 (handle_channel_announcement) DEBUG gossipd: gossipd/gossipd.c:238 (handle_channel_announcement_msg) DEBUG gossipd: gossipd/gossipd.c:444 (peer_msg_in) DEBUG gossipd: common/daemon_conn.c:31 (handle_read) DEBUG gossipd: ccan/ccan/io/io.c:59 (next_plan) DEBUG gossipd: ccan/ccan/io/io.c:407 (do_plan) DEBUG gossipd: ccan/ccan/io/io.c:417 (io_ready) DEBUG gossipd: ccan/ccan/io/poll.c:445 (io_loop) DEBUG gossipd: gossipd/gossipd.c:1730 (main) **BROKEN** gossipd: parents: **BROKEN** gossipd: gossipd/routing.c:1698:struct pending_cannouncement **BROKEN** gossipd: gossipd/gossipd.c:1700:struct daemon ``` Signed-off-by: Rusty Russell <[email protected]>
I wanted this for offers, and it's generally useful. Signed-off-by: Rusty Russell <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
e172b39
to
a211ddb
Compare
Thanks, fixed.... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK a211ddb
return NULL; | ||
|
||
/* Add one for nul term */ | ||
ret = tal_dup_arr(ctx, char, (const char *)buf, buflen, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the string is already null-terminated? Could we end up in a situation where we call utf8_str
multiple times, each time re-allocating it to append the \0
?
Signed-off-by: Rusty Russell <[email protected]>
Added rejection of UTF-8 strings with NUL in them (which makes sense, given the UTF-8 API). |
Misc stuff which happened on the way to offers.