Browse Source

ocb_init fix (preventing index overflow)

Karel Miko 13 years ago
parent
commit
c5c067fd12
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/encauth/ocb/ocb_init.c

+ 5 - 1
src/encauth/ocb/ocb_init.c

@@ -60,11 +60,15 @@ int ocb_init(ocb_state *ocb, int cipher,
 
    /* determine which polys to use */
    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) { 
           break;
        }
    }
+   if (poly == x) {
+      return CRYPT_INVALID_ARG; /* block_len not found in polys */
+   }
    if (polys[poly].len != ocb->block_len) {
       return CRYPT_INVALID_ARG;
    }