From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/287 Path: news.gmane.org!not-for-mail From: =?UTF-8?B?THVrYSBNYXLEjWV0acSH?= Newsgroups: gmane.linux.lib.musl.general Subject: Re: Simple testing task - string functions Date: Thu, 14 Apr 2011 19:59:33 +0200 Message-ID: <4DA73605.9080107@gmail.com> References: <20110410044515.GB13185@brightrain.aerifal.cx> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; X-Trace: dough.gmane.org 1312595705 11454 80.91.229.12 (6 Aug 2011 01:55:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2011 01:55:05 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: envelope-from@hidden Thu Apr 14 22:02:46 2011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; DomainKey-Signature: a=rsa-sha1; c=nofws; User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110402 Icedove/3.1.9 In-Reply-To: <20110410044515.GB13185@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:287 Archived-At: This is a multi-part message in MIME format. --------------080500010007030902050509 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello again. Attached is the solution to the task. The program seems to preform as expected, but may still need double-checking. The tests therein fail where expected when linked with various old versions of musl. Note that although the program is designed to allow tests to fail gracefully as suggested, this does not happen due to bugs in function implementations in said old versions that the program depends on. Rich and Chris have confirmed a bug in 0.7.6 that causes a segfault in the siglongjmp (longjmp to be exact). I'm still waiting for confirmation of inability of version 0.7.5 to dispose the same signal to a specified handler properly. Thanks. Luka Marčetić --------------080500010007030902050509 Content-Type: text/x-csrc; name="memory_access.c" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="memory_access.c" #include #include #include #include #include #include #include /** ** \file depends: sysconf, mmap, mprotect, open, signal, sigsetjmp, siglongjmp, fprintf ** \author Luka Marčetić, 2011 **/ //necessary to detect errors, and resume afterwards: int next; ///< number of the currently executing test, or greater on failure sigjmp_buf env; ///< will store the signal mask and stack context/environment void bridge_sig_jmp(int sig); void print_result(int done, char *name); /** ** Tests string/memory functions for invalid memory access ** and for correctnes when handling 'high' vs 'low' bytes. ** ** tests: strchr, strlen, strspn, strcspn, memchr **/ int main() { int i, j, k, fd, tmpi, pg_size=sysconf(_SC_PAGESIZE); char *tmp, *m; char low=' ', high=128+low, string[]="\x20\x40\x60\x80\xA0\xC0\xE0"; fd = open("/dev/zero", O_RDWR); m = mmap(NULL, pg_size*2, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); mprotect(m+pg_size, pg_size, PROT_NONE); signal(SIGSEGV, bridge_sig_jmp); next=0; switch (sigsetjmp(env, 1)) { case 0: //strchr: fprintf(stdout, " strchr\n"); for (i=0; i done) fprintf (stderr, " %s: Failure\n", name); else { fprintf (stdout, " %s: Success\n", name); next = done+1; } return; } --------------080500010007030902050509--