]> git.proxmox.com Git - mirror_kronosnet.git/commitdiff
[compress] do not overrun allocated array for compress modules
authorFabio M. Di Nitto <fdinitto@redhat.com>
Thu, 18 Jul 2019 13:39:57 +0000 (15:39 +0200)
committerFabio M. Di Nitto <fdinitto@redhat.com>
Tue, 23 Jul 2019 04:45:54 +0000 (06:45 +0200)
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
libknet/compress.c

index 1ed0dc5eda9c6a4f34cf3d9443d864d3f41b5627..20645a96eb3ed91a8cb638bb3ffa94c881883866 100644 (file)
@@ -32,7 +32,7 @@
  * Always add new items before the last NULL.
  */
 
-static compress_model_t compress_modules_cmds[] = {
+static compress_model_t compress_modules_cmds[KNET_MAX_COMPRESS_METHODS + 1] = {
        { "none" , 0, 0, 0, NULL },
        { "zlib" , 1, WITH_COMPRESS_ZLIB , 0, NULL },
        { "lz4"  , 2, WITH_COMPRESS_LZ4  , 0, NULL },
@@ -41,7 +41,7 @@ static compress_model_t compress_modules_cmds[] = {
        { "lzma" , 5, WITH_COMPRESS_LZMA , 0, NULL },
        { "bzip2", 6, WITH_COMPRESS_BZIP2, 0, NULL },
        { "zstd" , 7, WITH_COMPRESS_ZSTD, 0, NULL },
-       { NULL, 255, 0, 0, NULL }
+       { NULL, KNET_MAX_COMPRESS_METHODS, 0, 0, NULL }
 };
 
 static int max_model = 0;
@@ -387,8 +387,8 @@ void compress_fini(
                return;
        }
 
-       while (compress_modules_cmds[idx].model_name != NULL) {
-               if ((idx < KNET_MAX_COMPRESS_METHODS) && /* check idx first so we don't read bad data */
+       while (idx < KNET_MAX_COMPRESS_METHODS) {
+               if ((compress_modules_cmds[idx].model_name != NULL) &&
                    (compress_modules_cmds[idx].built_in == 1) &&
                    (compress_modules_cmds[idx].loaded == 1) &&
                    (compress_modules_cmds[idx].model_id > 0) &&