浏览代码

ocb3_init fix (preventing index overflow)

Karel Miko 13 年之前
父节点
当前提交
9c2193b722
共有 1 个文件被更改,包括 5 次插入1 次删除
  1. 5 1
      src/encauth/ocb3/ocb3_init.c

+ 5 - 1
src/encauth/ocb3/ocb3_init.c

@@ -64,11 +64,15 @@ int ocb3_init(ocb3_state *ocb, int cipher,
 
 
    /* determine which polys to use */
    /* determine which polys to use */
    ocb->block_len = cipher_descriptor[cipher].block_length;
    ocb->block_len = cipher_descriptor[cipher].block_length;
-   for (poly = 0; poly < (int)(sizeof(polys)/sizeof(polys[0])); poly++) {
+   x = (int)(sizeof(polys)/sizeof(polys[0]));
+   for (poly = 0; poly < x; poly++) {
        if (polys[poly].len == ocb->block_len) {
        if (polys[poly].len == ocb->block_len) {
           break;
           break;
        }
        }
    }
    }
+   if (poly == x) {
+      return CRYPT_INVALID_ARG; /* block_len not found in polys */
+   }
    if (polys[poly].len != ocb->block_len) {
    if (polys[poly].len != ocb->block_len) {
       return CRYPT_INVALID_ARG;
       return CRYPT_INVALID_ARG;
    }
    }