]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: var-expand - Avoid unsigned overflow in offset calculation
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 20 Aug 2020 06:44:20 +0000 (09:44 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 11 Sep 2020 07:07:20 +0000 (07:07 +0000)
src/lib/var-expand.c

index 4d785f068001d9db61f3a7e7a58e36e8c061e3f7..7ddaec0a63f93a3f11236f3990b1648d59f52cd1 100644 (file)
@@ -599,9 +599,10 @@ int var_expand_with_funcs(string_t *dest, const char *str,
                                        /* if offset is < 0 then we want to
                                           start at the end */
                                        size_t len = strlen(var);
+                                       size_t offset_from_end = -ctx.offset;
 
-                                       if (len > (size_t)-ctx.offset)
-                                               var += len + ctx.offset;
+                                       if (len > offset_from_end)
+                                               var += len - offset_from_end;
                                } else {
                                        while (*var != '\0' && ctx.offset > 0) {
                                                ctx.offset--;