From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/28 Path: news.gmane.org!not-for-mail From: JIghtuse Newsgroups: gmane.linux.lib.musl.general Subject: Re: malloc testing Date: Sun, 5 Jun 2011 01:03:18 +0700 Message-ID: References: <4DB78C5F.8030803@gmail.com> <20110429054235.GB27053@openwall.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=90e6ba53a940665edc04a4e6af1d X-Trace: dough.gmane.org 1307210627 5575 80.91.229.12 (4 Jun 2011 18:03:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 4 Jun 2011 18:03:47 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-111-gllmg-musl=m.gmane.org@lists.openwall.com Sat Jun 04 20:03:43 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1QSvCI-0002Im-LB for gllmg-musl@lo.gmane.org; Sat, 04 Jun 2011 20:03:42 +0200 Original-Received: (qmail 9384 invoked by uid 550); 4 Jun 2011 18:03:41 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9376 invoked from network); 4 Jun 2011 18:03:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=a7af4SkctohpW6bZmzlwjPDeNPVeMQmgfZIYBSpRlA0=; b=MGQvQtfcOwEiokWjhFcvkHjTZIah/V78/OwU01Ho5xe/IskTiFw5u4T848txfdKNO+ Ho+3WG31vw4i7fEnhEjNcSiINWcquiBZ1to7ZEHY0Ei67zM9MQmNXvFk+Htb4z/PO2w0 Lmqz+Ic1Ayf1qecLWWc7NNslTkrvSCdjOQbTM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=fo1iiEmllx2RfQPot10BFw5UAaf0aldh1uH73QttOxwZnphfatLpKu6oDDiLSS3G+H GaiDoAXJ5YLNUi1FGHm+t5IRo+ySQWEKs4fBaZ5WVmhnB8/+YBzuGn1NdzY7Rb2Yuc7c B389/f1sFkgJfEdH0lWZTLLEFDO0YwQuZmUZI= In-Reply-To: <20110429054235.GB27053@openwall.com> Xref: news.gmane.org gmane.linux.lib.musl.general:28 Archived-At: --90e6ba53a940665edc04a4e6af1d Content-Type: text/plain; charset=ISO-8859-1 On Fri, Apr 29, 2011 at 12:42 PM, Solar Designer wrote: > JIghtuse - > > On Wed, Apr 27, 2011 at 10:24:15AM +0700, JIghtuse wrote: > > So, I am still working on testing malloc() of musl. My coding breaks by > > some increase of studing in university, but I have to say I want to > > participate. Is it real to join Summer of Security? > > Sure. Thanks for the status update. > > > After finished musl tests > > Luka is the primary person to work on these, but you're welcome to stay > involved as well - e.g., you may help test Luka's tests against more > libc's, report problems in here (both those of the tests and of the > libc's), and improve the tests. > > > I want to try blists development also. > > Sounds good. This is off-topic for the musl list, though, so please > e-mail me off-list for it when you're ready. > > Thanks, > > Alexander > > P.S. Somehow you started a new thread instead of posting to the existing > thread with the same Subject. You should have used "reply" on a message > in the proper thread. > So, my program creates array of structures of memory blocks and works with it. Source code: #include #include #include #include #define M 100000000 #define REPEATS 10 struct block { unsigned int* ptr; unsigned int size; } blocks[M / 100]; int by_size(const void *, const void *); int by_address(const void *, const void *); int main(int argc, char *argv[]) { unsigned int i = 0, j, counter; unsigned int seed; unsigned int amount = 0; unsigned int size; if (argc > 1) { seed = atoi(argv[1]); } else { printf("Type seed: "); scanf("%u", &seed); } bzero(blocks, sizeof(blocks[0]) * (M / 100)); for (counter = 0; counter < REPEATS; counter++) { while (amount < M) { size = rand() % (M / 100); if (size > 100000) { size |= 0xff0; } blocks[i].size = size; blocks[i].ptr = malloc(sizeof(int) * size); if (blocks[i].ptr == NULL) { printf("\nmalloc() error!\n"); exit(EXIT_FAILURE); } amount += blocks[i].size; i++; } if (counter != REPEATS - 1) { qsort(blocks, i, sizeof(struct block), by_size); for (j = i / 4; j < i; j++) { amount -= blocks[j].size; free(blocks[j].ptr); } bzero((void *)(blocks + i / 4), sizeof(blocks[0]) * ((i / 4) * 3 + 3)); i /= 4; } else { qsort(blocks, i, sizeof(struct block), by_address); } } printf("%5s %12s %8s\n", "No.", "Address", "Size"); for (j = 0; j < i - 1; j++) { printf("%5u %12u %8u\n", j, (unsigned int)blocks[j].ptr, blocks[j].size); if (blocks[j].ptr + blocks[j].size >= blocks[j + 1].ptr) { printf("\nOverlaped!\n"); exit(EXIT_SUCCESS); } } printf("%5u %12u %8u\n", j, (unsigned int)blocks[j].ptr, blocks[j].size); exit (EXIT_SUCCESS); } int by_size(const void * a, const void * b) { struct block *ia = (struct block *)a; struct block *ib = (struct block *)b; return (int)(ia->size - ib->size); } int by_address(const void * a, const void * b) { struct block *ia = (struct block *)a; struct block *ib = (struct block *)b; return (void *)ia->ptr > (void *)ib->ptr; } Sample output: No. Address Size 0 167530504 5211 1 167551352 21530 2 167637480 18456 3 167711312 28624 <...> 266 3071238152 36159 267 3071651848 33333 268 3073114120 204799 269 3073937416 794617 I tried to plot this data with gnuplot, but it'll require parting data at two or more parts because of big address range. --90e6ba53a940665edc04a4e6af1d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Fri, Apr 29, 2011 at 12:42 PM, Solar = Designer <solar@= openwall.com> wrote:
JIghtuse -

On Wed, Apr 27, 2011 at 10:24:15AM +0700, JIghtuse wrote:
> So, I am still working on testing malloc() of musl. My coding breaks b= y
> some increase of studing in university, but I have to say I want to > participate. Is it real to join Summer of Security?

Sure. =A0Thanks for the status update.

> After finished musl tests

Luka is the primary person to work on these, but you're welcome to stay=
involved as well - e.g., you may help test Luka's tests against more libc's, report problems in here (both those of the tests and of the
libc's), and improve the tests.

> I want to try blists development also.

Sounds good. =A0This is off-topic for the musl list, though, so pleas= e
e-mail me off-list for it when you're ready.

Thanks,

Alexander

P.S. Somehow you started a new thread instead of posting to the existing thread with the same Subject. =A0You should have used "reply" on = a message
in the proper thread.

So, my program creates array of structures of memory= blocks and works with it.
Source code:

#include <stdio.h><= br>#include <stdlib.h>
#include <string.h>
#include <s= trings.h>

#define M 100000000
#define REPEATS 10

struct block {
=A0= =A0=A0 unsigned int* ptr;
=A0=A0=A0 unsigned int size;
} blocks[M / 1= 00];

int by_size(const void *, const void *);
int by_address(cons= t void *, const void *);

int main(int argc, char *argv[])
{
=A0=A0=A0 unsigned int i =3D 0= , j, counter;
=A0=A0=A0 unsigned int seed;
=A0=A0=A0 unsigned int amo= unt =3D 0;
=A0=A0=A0 unsigned int size;
=A0=A0=A0
=A0=A0=A0 if (a= rgc > 1) {
=A0=A0=A0 =A0=A0=A0 seed =3D atoi(argv[1]);
=A0=A0=A0 } else {
=A0=A0=A0 =A0=A0=A0 printf("Type seed: ");<= br>=A0=A0=A0 =A0=A0=A0 scanf("%u", &seed);
=A0=A0=A0 }
=
=A0=A0=A0 bzero(blocks, sizeof(blocks[0]) * (M / 100));

=A0=A0= =A0 for (counter =3D 0; counter < REPEATS; counter++) {
=A0=A0=A0 =A0=A0=A0 while (amount < M) {
=A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 size =3D rand() % (M / 100);
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 if (size = > 100000) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 size |=3D 0xff0;<= br>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }

=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 blo= cks[i].size =3D size;
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 blocks[i].ptr =3D ma= lloc(sizeof(int) * size);
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 if (blocks[i].ptr =3D=3D NULL) {
=A0=A0=A0= =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 printf("\nmalloc() error!\n");
= =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 exit(EXIT_FAILURE);
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 amount +=3D blocks[i= ].size;
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 i++;
=A0=A0=A0 =A0=A0=A0 }

=A0=A0=A0 =A0=A0=A0 if (counter !=3D REPEATS -= 1) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 qsort(blocks, i, sizeof(struct block= ), by_size);
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 for (j =3D i / 4; j < i; j= ++) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 amount -=3D blocks[j].size= ;
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 free(blocks[j].ptr);
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 bzero((voi= d *)(blocks + i / 4), sizeof(blocks[0]) * ((i / 4) * 3 + 3));
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 i /=3D 4;
=A0=A0=A0 =A0=A0=A0 } else {
=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 qsort(blocks, i, sizeof(struct block), by_address);
= =A0=A0=A0 =A0=A0=A0 }=A0=A0=A0
=A0=A0=A0 }
=A0=A0=A0
=A0=A0=A0 printf("%5s %12s %8s\n", &= quot;No.", "Address", "Size");
=A0=A0=A0 for (j= =3D 0; j < i - 1; j++) {
=A0=A0=A0 =A0=A0=A0 printf("%5u %12u %= 8u\n", j, (unsigned int)blocks[j].ptr, blocks[j].size);
=A0=A0=A0 =A0=A0=A0 if (blocks[j].ptr + blocks[j].size >=3D blocks[j + 1= ].ptr) {
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 printf("\nOverlaped!\n"= );
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 exit(EXIT_SUCCESS);
=A0=A0=A0 =A0=A0= =A0 }
=A0=A0=A0 }
=A0=A0=A0 printf("%5u %12u %8u\n", j, (un= signed int)blocks[j].ptr, blocks[j].size);
=A0=A0=A0 exit (EXIT_SUCCESS);
}

int by_size(const void * a, cons= t void * b)
{
=A0 struct block *ia =3D (struct block *)a;
=A0 stru= ct block *ib =3D (struct block *)b;
=A0 return (int)(ia->size - ib-&g= t;size);
}

int by_address(const void * a, const void * b)
{
=A0=A0=A0 s= truct block *ia =3D (struct block *)a;
=A0=A0=A0 struct block *ib =3D (s= truct block *)b;
=A0=A0=A0 return (void *)ia->ptr > (void *)ib->= ;ptr;
}




Sample output:
=A0 No.=A0=A0=A0=A0=A0 Address=A0=A0=A0=A0 Si= ze
=A0=A0=A0 0=A0=A0=A0 167530504=A0=A0=A0=A0 5211
=A0=A0=A0 1=A0=A0= =A0 167551352=A0=A0=A0 21530
=A0=A0=A0 2=A0=A0=A0 167637480=A0=A0=A0 184= 56
=A0=A0=A0 3=A0=A0=A0 167711312=A0=A0=A0 28624
<...>
=A0 2= 66=A0=A0 3071238152=A0=A0=A0 36159
=A0 267=A0=A0 3071651848=A0=A0=A0 33333
=A0 268=A0=A0 3073114120=A0=A0 2= 04799
=A0 269=A0=A0 3073937416=A0=A0 794617


I tried to plot t= his data with gnuplot, but it'll require parting data at two or more pa= rts because of big address range.
--90e6ba53a940665edc04a4e6af1d--