소스 검색

assert that nobody asks for a random number between 0 and -1

svn:r875
Roger Dingledine 20 년 전
부모
커밋
05b9c35173
1개의 변경된 파일1개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      src/common/crypto.c

+ 1 - 0
src/common/crypto.c

@@ -1013,6 +1013,7 @@ int crypto_pseudo_rand_int(unsigned int max) {
   unsigned int val;
   unsigned int cutoff;
   assert(max < UINT_MAX);
+  assert(max > 0); /* don't div by 0 */
 
   /* We ignore any values that are >= 'cutoff,' to avoid biasing the
    * distribution with clipping at the upper end of unsigned int's