From: Martin Quinson Date: Mon, 8 Oct 2012 23:24:21 +0000 (+0200) Subject: try harder to break mmalloc wrt double-free X-Git-Tag: v3_8~97^2~3 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3ca7b9a135ee10337486c6473f582419c5c23241 try harder to break mmalloc wrt double-free --- diff --git a/teshsuite/xbt/mmalloc.tesh b/teshsuite/xbt/mmalloc.tesh index 4244e057ff..e584decb3e 100644 --- a/teshsuite/xbt/mmalloc.tesh +++ b/teshsuite/xbt/mmalloc.tesh @@ -11,6 +11,46 @@ $ ./xbt/mmalloc_test --log=root.fmt:%m%n > 800 bytes allocated with offset 1513472 > 900 bytes allocated with offset 1512448 > 1000 bytes allocated with offset 1515520 +> 1100 bytes allocated with offset 1519616 +> 1200 bytes allocated with offset 1521664 +> 1300 bytes allocated with offset 1523712 +> 1400 bytes allocated with offset 1525760 +> 1500 bytes allocated with offset 1527808 +> 1600 bytes allocated with offset 1529856 +> 1700 bytes allocated with offset 1531904 +> 1800 bytes allocated with offset 1533952 +> 1900 bytes allocated with offset 1536000 +> 2000 bytes allocated with offset 1538048 +> 2100 bytes allocated with offset 1540096 +> 2200 bytes allocated with offset 1544192 +> 2300 bytes allocated with offset 1548288 +> 2400 bytes allocated with offset 1552384 +> 2500 bytes allocated with offset 1556480 +> 2600 bytes allocated with offset 1560576 +> 2700 bytes allocated with offset 1564672 +> 2800 bytes allocated with offset 1568768 +> 2900 bytes allocated with offset 1572864 +> 3000 bytes allocated with offset 1576960 +> 3100 bytes allocated with offset 1581056 +> 3200 bytes allocated with offset 1585152 +> 3300 bytes allocated with offset 1589248 +> 3400 bytes allocated with offset 1593344 +> 3500 bytes allocated with offset 1597440 +> 3600 bytes allocated with offset 1601536 +> 3700 bytes allocated with offset 1605632 +> 3800 bytes allocated with offset 1609728 +> 3900 bytes allocated with offset 1613824 +> 4000 bytes allocated with offset 1617920 +> 4100 bytes allocated with offset 1622016 +> 4200 bytes allocated with offset 1630208 +> 4300 bytes allocated with offset 1638400 +> 4400 bytes allocated with offset 1646592 +> 4500 bytes allocated with offset 1654784 +> 4600 bytes allocated with offset 1662976 +> 4700 bytes allocated with offset 1671168 +> 4800 bytes allocated with offset 1679360 +> 4900 bytes allocated with offset 1687552 +> 5000 bytes allocated with offset 1695744 > 100 bytes allocated with offset 1506816 > 200 bytes allocated with offset 1506560 > 300 bytes allocated with offset 1509888 @@ -19,87 +59,50 @@ $ ./xbt/mmalloc_test --log=root.fmt:%m%n > 600 bytes allocated with offset 1518592 > 700 bytes allocated with offset 1517568 > 800 bytes allocated with offset 1516544 -> 900 bytes allocated with offset 1519616 -> 1000 bytes allocated with offset 1522688 -> 100 bytes allocated with offset 1506304 -> 200 bytes allocated with offset 1506048 -> 300 bytes allocated with offset 1508352 -> 400 bytes allocated with offset 1507840 -> 500 bytes allocated with offset 1523712 -> 600 bytes allocated with offset 1521664 -> 700 bytes allocated with offset 1520640 -> 800 bytes allocated with offset 1527808 -> 900 bytes allocated with offset 1530880 -> 1000 bytes allocated with offset 1529856 -> 100 bytes allocated with offset 1505792 -> 200 bytes allocated with offset 1505536 -> 300 bytes allocated with offset 1527296 -> 400 bytes allocated with offset 1526784 -> 500 bytes allocated with offset 1526272 -> 600 bytes allocated with offset 1528832 -> 700 bytes allocated with offset 1531904 -> 800 bytes allocated with offset 1534976 -> 900 bytes allocated with offset 1533952 -> 1000 bytes allocated with offset 1532928 -> 100 bytes allocated with offset 1505280 -> 200 bytes allocated with offset 1505024 -> 300 bytes allocated with offset 1525760 -> 400 bytes allocated with offset 1525248 -> 500 bytes allocated with offset 1524736 -> 600 bytes allocated with offset 1536000 -> 700 bytes allocated with offset 1539072 -> 800 bytes allocated with offset 1538048 -> 900 bytes allocated with offset 1537024 -> 1000 bytes allocated with offset 1540096 -> 100 bytes allocated with offset 1504768 -> 200 bytes allocated with offset 1504512 -> 300 bytes allocated with offset 1524224 -> 400 bytes allocated with offset 1544192 -> 500 bytes allocated with offset 1547776 -> 600 bytes allocated with offset 1543168 -> 700 bytes allocated with offset 1542144 -> 800 bytes allocated with offset 1541120 -> 900 bytes allocated with offset 1548288 -> 1000 bytes allocated with offset 1551360 -> 100 bytes allocated with offset 1504256 -> 200 bytes allocated with offset 1504000 -> 300 bytes allocated with offset 1547264 -> 400 bytes allocated with offset 1546752 -> 500 bytes allocated with offset 1546240 -> 600 bytes allocated with offset 1550336 -> 700 bytes allocated with offset 1549312 -> 800 bytes allocated with offset 1552384 -> 900 bytes allocated with offset 1555456 -> 1000 bytes allocated with offset 1554432 -> 100 bytes allocated with offset 1503744 -> 200 bytes allocated with offset 1503488 -> 300 bytes allocated with offset 1545728 -> 400 bytes allocated with offset 1545216 -> 500 bytes allocated with offset 1544704 -> 600 bytes allocated with offset 1553408 -> 700 bytes allocated with offset 1556480 -> 800 bytes allocated with offset 1559552 -> 900 bytes allocated with offset 1558528 -> 1000 bytes allocated with offset 1557504 -> 100 bytes allocated with offset 1560576 -> 200 bytes allocated with offset 1564416 -> 300 bytes allocated with offset 1564672 -> 400 bytes allocated with offset 1568256 -> 500 bytes allocated with offset 1567744 -> 600 bytes allocated with offset 1568768 -> 700 bytes allocated with offset 1571840 -> 800 bytes allocated with offset 1570816 -> 900 bytes allocated with offset 1569792 -> 1000 bytes allocated with offset 1572864 -> 100 bytes allocated with offset 1564160 -> 200 bytes allocated with offset 1563904 -> 300 bytes allocated with offset 1567232 -> 400 bytes allocated with offset 1566720 -> 500 bytes allocated with offset 1566208 -> 600 bytes allocated with offset 1575936 -> 700 bytes allocated with offset 1574912 -> 800 bytes allocated with offset 1573888 -> 900 bytes allocated with offset 1576960 -> 1000 bytes allocated with offset 1580032 -> Done; bye bye - +> 900 bytes allocated with offset 1703936 +> 1000 bytes allocated with offset 1707008 +> 1100 bytes allocated with offset 1708032 +> 1200 bytes allocated with offset 1710080 +> 1300 bytes allocated with offset 1712128 +> 1400 bytes allocated with offset 1714176 +> 1500 bytes allocated with offset 1716224 +> 1600 bytes allocated with offset 1718272 +> 1700 bytes allocated with offset 1720320 +> 1800 bytes allocated with offset 1722368 +> 1900 bytes allocated with offset 1724416 +> 2000 bytes allocated with offset 1726464 +> 2100 bytes allocated with offset 1728512 +> 2200 bytes allocated with offset 1732608 +> 2300 bytes allocated with offset 1736704 +> 2400 bytes allocated with offset 1740800 +> 2500 bytes allocated with offset 1744896 +> 2600 bytes allocated with offset 1748992 +> 2700 bytes allocated with offset 1753088 +> 2800 bytes allocated with offset 1757184 +> 2900 bytes allocated with offset 1761280 +> 3000 bytes allocated with offset 1765376 +> 3100 bytes allocated with offset 1769472 +> 3200 bytes allocated with offset 1773568 +> 3300 bytes allocated with offset 1777664 +> 3400 bytes allocated with offset 1781760 +> 3500 bytes allocated with offset 1785856 +> 3600 bytes allocated with offset 1789952 +> 3700 bytes allocated with offset 1794048 +> 3800 bytes allocated with offset 1798144 +> 3900 bytes allocated with offset 1802240 +> 4000 bytes allocated with offset 1806336 +> 4100 bytes allocated with offset 1810432 +> 4200 bytes allocated with offset 1818624 +> 4300 bytes allocated with offset 1826816 +> 4400 bytes allocated with offset 1835008 +> 4500 bytes allocated with offset 1843200 +> 4600 bytes allocated with offset 1851392 +> 4700 bytes allocated with offset 1859584 +> 4800 bytes allocated with offset 1867776 +> 4900 bytes allocated with offset 1875968 +> 5000 bytes allocated with offset 1884160 +> All blocks were correctly allocated. Free every second block +> Re-allocate every second block +> free all blocks (each one twice, to check that double free are correctly catched) +> free again all blocks (to really check that double free are correctly catched) +> Damnit, I cannot break mmalloc this time. That's SO disappointing. diff --git a/teshsuite/xbt/mmalloc_test.c b/teshsuite/xbt/mmalloc_test.c index dc1e6d9e30..0c21dfdd1e 100644 --- a/teshsuite/xbt/mmalloc_test.c +++ b/teshsuite/xbt/mmalloc_test.c @@ -12,6 +12,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test,"this test"); #define BUFFSIZE 204800 #define TESTSIZE 100 +#define size_of_block(i) (((i % 50)+1)* 100) int main(int argc, char**argv) { @@ -31,11 +32,22 @@ int main(int argc, char**argv) int i, size; for (i = 0; i < TESTSIZE; i++) { - size = ((i % 10)+1)* 100; + size = size_of_block(i); pointers[i] = mmalloc(heapA, size); XBT_INFO("%d bytes allocated with offset %lu", size, ((char*)pointers[i])-((char*)heapA)); } + XBT_INFO("All blocks were correctly allocated. Free every second block"); + for (i = 0; i < TESTSIZE; i+=2) { + size = size_of_block(i); + mfree(heapA,pointers[i]); + } + XBT_INFO("Re-allocate every second block"); + for (i = 0; i < TESTSIZE; i+=2) { + size = size_of_block(i); + pointers[i] = mmalloc(heapA, size); + } + XBT_INFO("free all blocks (each one twice, to check that double free are correctly catched)"); for (i = 0; i < TESTSIZE; i++) { xbt_ex_t e; int gotit = 1; @@ -48,9 +60,25 @@ int main(int argc, char**argv) xbt_ex_free(e); } if (!gotit) - xbt_die("FAIL: A double-free went undetected (for size:%d)",((i%10)+1)*100); + xbt_die("FAIL: A double-free went undetected (for size:%d)",size_of_block(i)); } - XBT_INFO("Done; bye bye"); + XBT_INFO("free again all blocks (to really check that double free are correctly catched)"); + for (i = 0; i < TESTSIZE; i++) { + xbt_ex_t e; + int gotit = 1; + + TRY { + mfree(heapA, pointers[i]); + gotit = 0; + } CATCH(e) { + xbt_ex_free(e); + } + if (!gotit) + xbt_die("FAIL: A double-free went undetected (for size:%d)",size_of_block(i)); + } + + + XBT_INFO("Damnit, I cannot break mmalloc this time. That's SO disappointing."); return 0; }