From: Alan T. DeKok Date: Wed, 6 Oct 2021 20:14:21 +0000 (-0400) Subject: add fr_strerror() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=611877de3d1ea7f0488e13d1b76b41dfaca6250d;p=thirdparty%2Ffreeradius-server.git add fr_strerror() --- diff --git a/src/lib/util/struct.c b/src/lib/util/struct.c index 50e4428c14e..4ff7ffa7a5b 100644 --- a/src/lib/util/struct.c +++ b/src/lib/util/struct.c @@ -77,7 +77,10 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_dcursor_t *cursor, unsigned int offset = 0; TALLOC_CTX *child_ctx; - if (data_len < 1) return -1; /* at least one byte of data */ + if (data_len == 0) { + fr_strerror_const("struct decoder was passed zero bytes of data"); + return -1; /* at least one byte of data */ + } FR_PROTO_HEX_DUMP(data, data_len, "fr_struct_from_network"); @@ -92,7 +95,11 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_dcursor_t *cursor, fr_assert(parent->type == FR_TYPE_STRUCT); struct_vp = fr_pair_afrom_da(ctx, parent); - if (!struct_vp) return -1; + if (!struct_vp) { + oom: + fr_strerror_const("out of memory"); + return -1; + } fr_pair_list_init(&head); /* still used elsewhere */ fr_dcursor_init(&child_cursor, &struct_vp->vp_group); @@ -298,7 +305,7 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_dcursor_t *cursor, } vp = fr_raw_from_network(ctx, parent, data, data_len); - if (!vp) return -1; + if (!vp) goto oom; /* * And append this one VP to the output cursor. @@ -363,7 +370,7 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_dcursor_t *cursor, if (!vp) { FR_PROTO_TRACE("Failed creating raw VP from malformed or unknown substruct"); fr_dict_unknown_free(&child); - return -(p - data); + goto oom; } fr_dcursor_append(&child_cursor, vp);