]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
config: old_settings_ssl_dh_read() - Replace while() from non-iterating code
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 18 Jan 2022 13:26:30 +0000 (14:26 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 20 Jan 2022 20:59:57 +0000 (20:59 +0000)
Found by code analysis tool

src/config/old-set-parser.c

index d5302f8689c7761de319f978b97c8585b72e44f4..940ac41760fd63bc2c20893873830d33a1e1abeb 100644 (file)
@@ -102,19 +102,19 @@ static bool old_settings_ssl_dh_read(const char **value, const char **error_r)
        }
 
        /* then try to read the rest of the data */
-       while(i_stream_read(is) > 0) {
+       if (i_stream_read(is) > 0) {
                const unsigned char *buf = i_stream_get_data(is, &siz);
-               if (siz < 88) break;
-               memcpy(&keysize, buf, 2);
-               if (keysize == 512) {
-                       memcpy(&off, buf+4, 4);
-                       off += 16; // skip headers
-               } else {
-                       off = 8; // skip header
+               if (siz >= 88) {
+                       memcpy(&keysize, buf, 2);
+                       if (keysize == 512) {
+                               memcpy(&off, buf+4, 4);
+                               off += 16; // skip headers
+                       } else {
+                               off = 8; // skip header
+                       }
+                       if (off <= siz)
+                               buffer_append(data, buf+off, siz);
                }
-               if (off > siz) break;
-               buffer_append(data, buf+off, siz);
-               break;
        }
 
        const void *tmp = buffer_get_data(data, &siz);