Browse Source

wire: expose fromwire_fail to allow others to use it to mark failure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
f7bd95173d
  1. 12
      wire/fromwire.c
  2. 1
      wire/wire.h

12
wire/fromwire.c

@ -10,7 +10,7 @@
#include <type_to_string.h> #include <type_to_string.h>
/* Sets *cursor to NULL and returns NULL when extraction fails. */ /* Sets *cursor to NULL and returns NULL when extraction fails. */
static const void *fail_pull(const u8 **cursor, size_t *max) const void *fromwire_fail(const u8 **cursor, size_t *max)
{ {
*cursor = NULL; *cursor = NULL;
*max = 0; *max = 0;
@ -25,7 +25,7 @@ const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n)
/* Just make sure we don't leak uninitialized mem! */ /* Just make sure we don't leak uninitialized mem! */
if (copy) if (copy)
memset(copy, 0, n); memset(copy, 0, n);
return fail_pull(cursor, max); return fromwire_fail(cursor, max);
} }
*cursor += n; *cursor += n;
*max -= n; *max -= n;
@ -88,7 +88,7 @@ bool fromwire_bool(const u8 **cursor, size_t *max)
if (!fromwire(cursor, max, &ret, sizeof(ret))) if (!fromwire(cursor, max, &ret, sizeof(ret)))
return false; return false;
if (ret != 0 && ret != 1) if (ret != 0 && ret != 1)
fail_pull(cursor, max); fromwire_fail(cursor, max);
return ret; return ret;
} }
@ -103,7 +103,7 @@ void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)
* See towire_gossip_resolve_channel_reply --RR */ * See towire_gossip_resolve_channel_reply --RR */
if (!memeqzero(der, sizeof(der)) if (!memeqzero(der, sizeof(der))
&& !pubkey_from_der(der, sizeof(der), pubkey)) && !pubkey_from_der(der, sizeof(der), pubkey))
fail_pull(cursor, max); fromwire_fail(cursor, max);
} }
void fromwire_secret(const u8 **cursor, size_t *max, struct secret *secret) void fromwire_secret(const u8 **cursor, size_t *max, struct secret *secret)
@ -126,7 +126,7 @@ void fromwire_secp256k1_ecdsa_signature(const u8 **cursor,
if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, sig, compact) if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, sig, compact)
!= 1) != 1)
fail_pull(cursor, max); fromwire_fail(cursor, max);
} }
void fromwire_channel_id(const u8 **cursor, size_t *max, void fromwire_channel_id(const u8 **cursor, size_t *max,
@ -182,7 +182,7 @@ void fromwire_ipaddr(const u8 **cursor, size_t *max, struct ipaddr *addr)
addr->addrlen = 16; addr->addrlen = 16;
break; break;
default: default:
fail_pull(cursor, max); fromwire_fail(cursor, max);
return; return;
} }
fromwire(cursor, max, addr->addr, addr->addrlen); fromwire(cursor, max, addr->addr, addr->addrlen);

1
wire/wire.h

@ -49,6 +49,7 @@ void derive_channel_id(struct channel_id *channel_id,
/* Read the type; returns -1 if not long enough. cursor is a tal ptr. */ /* Read the type; returns -1 if not long enough. cursor is a tal ptr. */
int fromwire_peektype(const u8 *cursor); int fromwire_peektype(const u8 *cursor);
const void *fromwire_fail(const u8 **cursor, size_t *max);
void towire(u8 **pptr, const void *data, size_t len); void towire(u8 **pptr, const void *data, size_t len);
void towire_pubkey(u8 **pptr, const struct pubkey *pubkey); void towire_pubkey(u8 **pptr, const struct pubkey *pubkey);

Loading…
Cancel
Save