]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
No need to create all those temporary sbuffs if the input data is empty
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 3 Feb 2022 16:25:12 +0000 (11:25 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 3 Feb 2022 16:25:12 +0000 (11:25 -0500)
src/lib/unlang/xlat_builtin.c

index 261e32a933eede2ab532d73c3bc47a5c5cbb319c..7615ef7202356728b646a9e3ebd4a26c37a697df 100644 (file)
@@ -1693,8 +1693,15 @@ static xlat_action_t xlat_func_lpad(UNUSED TALLOC_CTX *ctx, fr_dcursor_t *out,
 
                fr_sbuff_init_in(&sbuff, buff, pad_len);
                fr_sbuff_marker(&m_data, &sbuff);
-               fr_sbuff_advance(&m_data, pad_len - len);       /* Mark where we want the data to go */
-               fr_sbuff_move(&FR_SBUFF(&m_data), &FR_SBUFF(&sbuff), len); /* Shift the data */
+
+               /*
+                *      ...nothing to move if the input
+                *      string is empty.
+                */
+               if (len > 0) {
+                       fr_sbuff_advance(&m_data, pad_len - len);       /* Mark where we want the data to go */
+                       fr_sbuff_move(&FR_SBUFF(&m_data), &FR_SBUFF(&sbuff), len); /* Shift the data */
+               }
 
                if (fill_len == 1) {
                        memset(fr_sbuff_current(&sbuff), *fill_str, fr_sbuff_ahead(&m_data));