mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-26 20:30:59 +01:00
common/gossmap: don't memcpy NULL, 0, and don't add 0 to NULL pointer.
Of course, NULL and length 0 are natural partners, but We Can't Have Nice Things. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3be36a66e3
commit
2005ca436e
2 changed files with 7 additions and 3 deletions
|
@ -808,7 +808,9 @@ bool gossmap_local_addchan(struct gossmap_localmods *localmods,
|
||||||
be16 = cpu_to_be16(tal_bytelen(features));
|
be16 = cpu_to_be16(tal_bytelen(features));
|
||||||
memcpy(localmods->local + off, &be16, sizeof(be16));
|
memcpy(localmods->local + off, &be16, sizeof(be16));
|
||||||
off += sizeof(be16);
|
off += sizeof(be16);
|
||||||
memcpy(localmods->local + off, features, tal_bytelen(features));
|
/* Damn you, C committee! */
|
||||||
|
if (features)
|
||||||
|
memcpy(localmods->local + off, features, tal_bytelen(features));
|
||||||
off += tal_bytelen(features);
|
off += tal_bytelen(features);
|
||||||
|
|
||||||
/* Skip chain_hash */
|
/* Skip chain_hash */
|
||||||
|
|
|
@ -32,9 +32,11 @@ const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n)
|
||||||
SUPERVERBOSE("less than encoding length");
|
SUPERVERBOSE("less than encoding length");
|
||||||
return fromwire_fail(cursor, max);
|
return fromwire_fail(cursor, max);
|
||||||
}
|
}
|
||||||
*cursor += n;
|
/* ubsan: runtime error: applying zero offset to null pointer */
|
||||||
|
if (*cursor)
|
||||||
|
*cursor += n;
|
||||||
*max -= n;
|
*max -= n;
|
||||||
if (copy)
|
if (copy && n)
|
||||||
memcpy(copy, p, n);
|
memcpy(copy, p, n);
|
||||||
return memcheck(p, n);
|
return memcheck(p, n);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue