]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add fr_strerror()
authorAlan T. DeKok <aland@freeradius.org>
Wed, 6 Oct 2021 20:14:21 +0000 (16:14 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 6 Oct 2021 20:14:21 +0000 (16:14 -0400)
src/lib/util/struct.c

index 50e4428c14e802100576ad6be1052ac07a8e5c7d..4ff7ffa7a5b134c77477f288c86e7b3867a1a247 100644 (file)
@@ -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);