From: Arran Cudbard-Bell Date: Sat, 18 Mar 2023 04:40:17 +0000 (-0400) Subject: tacacs: Move packet code check to before the main encoder? X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93885589666b73e660d42d94bd5a330483f58914;p=thirdparty%2Ffreeradius-server.git tacacs: Move packet code check to before the main encoder? --- diff --git a/src/protocols/tacacs/encode.c b/src/protocols/tacacs/encode.c index 70106131c16..bfc5c5d11c0 100644 --- a/src/protocols/tacacs/encode.c +++ b/src/protocols/tacacs/encode.c @@ -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