Ticket #13104: 02-tor-memeq-arith-undef.patch

File 02-tor-memeq-arith-undef.patch, 1.6 KB (added by teor, 5 years ago)

Even more exhaustively test tor_memeq and tor_memcmp - no tor code changes

  • src/test/test_util.c

    diff --git a/src/test/test_util.c b/src/test/test_util.c
    index 2692f36..4c7a293 100644
    a b test_util_di_ops(void) 
    33593365    test_eq(neq1, !eq1);
    33603366  }
    33613367
    3362   /* exhaustively white-box test tor_memeq
    3363    * against each possible (single-byte) bit difference
    3364    * some arithmetic bugs only appear with certain bit patterns */
    33653368  {
    3366   uint8_t zz = 0;
    3367   uint8_t ii = 0;
    3368   int z;
    3369   for (i = 0; i < 256; i++) {
    3370     ii = (uint8_t)i;
    3371     test_eq(tor_memeq(&zz, &ii, 1), zz == ii);
    3372   }
    3373 
    3374   /* exhaustively white-box test tor_memcmp
    3375    * against each possible single-byte numeric difference
    3376    * some arithmetic bugs only appear with certain bit patterns */
    3377   for (z = 0; z < 256; z++) {
    3378     for (i = 0; i < 256; i++) {
    3379       ii = (uint8_t)i;
    3380       zz = (uint8_t)z;
    3381       test_eq(tor_memcmp(&zz, &ii, 1) > 0 ? GT : EQ, zz > ii ? GT : EQ);
    3382       test_eq(tor_memcmp(&ii, &zz, 1) < 0 ? LT : EQ, ii < zz ? LT : EQ);
     3369    uint8_t zz = 0;
     3370    uint8_t ii = 0;
     3371    int z;
     3372
     3373    /* exhaustively test tor_memeq and tor_memcmp
     3374     * against each possible single-byte numeric difference
     3375     * some arithmetic bugs only appear with certain bit patterns */
     3376    for (z = 0; z < 256; z++) {
     3377      for (i = 0; i < 256; i++) {
     3378        ii = (uint8_t)i;
     3379        zz = (uint8_t)z;
     3380        test_eq(tor_memeq(&zz, &ii, 1), zz == ii);
     3381        test_eq(tor_memcmp(&zz, &ii, 1) > 0 ? GT : EQ, zz > ii ? GT : EQ);
     3382        test_eq(tor_memcmp(&ii, &zz, 1) < 0 ? LT : EQ, ii < zz ? LT : EQ);
     3383      }
    33833384    }
    33843385  }
    3385   }
    33863386
    33873387  tt_int_op(1, ==, safe_mem_is_zero("", 0));
    33883388  tt_int_op(1, ==, safe_mem_is_zero("", 1));