lnsocket

A minimal C library for connecting to the lightning network
git clone git://jb55.com/lnsocket
Log | Files | Refs | Submodules | README | LICENSE

commit 496407d29ddae7db3a6bcb33e87eb73801d50a7e
parent e6e7c23a1f47325f6be592d281ac537bff49f700
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  3 Mar 2022 13:05:31 -0800

lnrpc: don't allow interleaved messages

I've seen this happen on iOS, let's make sure it doesn't happen here

Diffstat:
Mrpc.c | 11++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/rpc.c b/rpc.c @@ -94,19 +94,16 @@ int main(int argc, const char *argv[]) if (!(ok = lnsocket_recv(ln, &msgtype, &buf, &len))) goto done; - printf("%.*s", len - 8, buf + 8); - switch (msgtype) { case COMMANDO_REPLY_TERM: - printf("\n"); + printf("%.*s\n", len - 8, buf + 8); goto done; case COMMANDO_REPLY_CONTINUES: + printf("%.*s", len - 8, buf + 8); continue; default: - printf("\n"); - fprintf(stderr, "unknown msgtype %d\n", msgtype); - ok = 0; - goto done; + // ignore extra interleaved messages which can happen + continue; } }