]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
tacacs: Move packet code check to before the main encoder?
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 18 Mar 2023 04:40:17 +0000 (00:40 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 27 Mar 2023 22:59:42 +0000 (16:59 -0600)
src/protocols/tacacs/encode.c

index 70106131c1607f8eb169d2823e4c7fdec6e3504a..bfc5c5d11c073470f33269872e481c3dc1d0f8c3 100644 (file)
@@ -421,6 +421,16 @@ ssize_t fr_tacacs_encode(fr_dbuff_t *dbuff, uint8_t const *original_packet, char
                if (vp->da->parent == attr_tacacs_packet) break;
        }
 
+       /*
+        *      Force the correct header type, and randomly-placed
+        *      status fields.  But only if there's no code field.
+        *      Only the unit tests pass a zero code field, as that's
+        *      normally invalid.  The unit tests ensure that all of
+        *      the VPs are passed to encode a packet, and they all
+        *      must be correct
+        */
+       if (code && (fr_tacacs_code_to_packet(packet, code) < 0)) return -1;
+
        /*
         *      No "Packet" struct to encode.  We MUST have an original packet to copy the various fields
         *      from.
@@ -938,16 +948,6 @@ ssize_t fr_tacacs_encode(fr_dbuff_t *dbuff, uint8_t const *original_packet, char
                return -1;
        }
 
-       /*
-        *      Force the correct header type, and randomly-placed
-        *      status fields.  But only if there's no code field.
-        *      Only the unit tests pass a zero code field, as that's
-        *      normally invalid.  The unit tests ensure that all of
-        *      the VPs are passed to encode a packet, and they all
-        *      must be correct
-        */
-       if (code && (fr_tacacs_code_to_packet(packet, code) < 0)) return -1;
-
        /*
         *      The packet length we store in the header doesn't
         *      include the size of the header.  But we tell the