From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/238 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: cluts weekly reports Date: Wed, 3 Aug 2011 18:53:57 -0400 Message-ID: <20110803225357.GC132@brightrain.aerifal.cx> References: <20110803005619.GA2378@openwall.com> <20110803012112.GT132@brightrain.aerifal.cx> <4E3949E3.4090008@gmail.com> <20110803133155.GV132@brightrain.aerifal.cx> <4E398092.8070907@gmail.com> <20110803172227.GX132@brightrain.aerifal.cx> <4E398D5A.6080207@gmail.com> <20110803181908.GZ132@brightrain.aerifal.cx> <4E39C4D8.7040403@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1312412767 16098 80.91.229.12 (3 Aug 2011 23:06:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 3 Aug 2011 23:06:07 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-322-gllmg-musl=m.gmane.org@lists.openwall.com Thu Aug 04 01:06:03 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 1QokVn-0003mp-KM for gllmg-musl@lo.gmane.org; Thu, 04 Aug 2011 01:06:03 +0200 Original-Received: (qmail 1722 invoked by uid 550); 3 Aug 2011 23:06:03 -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 1714 invoked from network); 3 Aug 2011 23:06:02 -0000 Content-Disposition: inline In-Reply-To: <4E39C4D8.7040403@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:238 Archived-At: On Wed, Aug 03, 2011 at 11:59:52PM +0200, Luka Marčetić wrote: > [ > { > "include" : "stdlib.h", > "function": "char *realpath(const char *restrict file_name, char *restrict resolved_name);", > "data" : [ > { > "file_name": ["\".\"", "\"./123456789\""], > "resolved_name": "NULL", > > "return": "NULL", > "errno" : "ENAMETOOLONG" > } > ] > } > ] OK, I'm imagining something like this: void test_realpath(const struct test *test, void *res, char *buf, size_t len) { *(char *)res = realpath(test->arg[0].ptr, buf); } struct test tests[] = { { .function = test_realpath, .arg[0].ptr = ".", ... }, { .function = test_realpath, .arg[0].ptr = "./123456789", ... }, ...}; With some extra fields to indicate the return type and how the caller should validate the result. Actually I would make a function (called do_test or something) that would do all that work. Note that here I hard-coded the fact that tests will take a buffer/length pair (despite the fact that realpath ignores the length), but you could just as easily have encapsulated the args that the caller might vary into a separate void * argument to test_xxxxxxx() (which it would know how to cast back and extract data from. The result handling could also be better. Actually you might want to consider having the test structure include a "validate" function pointer that would be used to validate the results. A couple reusable validator functions would be one that strcmp's the contents of a buffer (and checks for overwrite at the end), one that compares an integer or floating point result stored at the result pointer, etc.. In addition, the generic code could always check errno unless you have a flag not to check it, or you could make a system where you provide an *array* of validator functions to choose the ones you want, thereby being able to include an errno check and something else. This is all very general stuff I whipped up in 30 minutes or so. I could elaborate on it if this isn't giving you enough ideas. Also, if you think this isn't helpful, please expand on the example you sent me. Seeing ONE TEST doesn't give me any idea of the type of generality you're trying to achieve. Also.. > for (f=0; f memset(&error, 0, sizeof(error)); > sigaction(SIGSEGV, &act, &oldact); > sig = 0; > for (d=0; !(sig = setjmp(env)) && !memcmp(&error, &no_error, sizeof(error)) && d arg = t[f].data[d].arg; //shorthand args > for (i=0; !memcmp(&error, &no_error, sizeof(error)) && i switch (f) { > case 0: > if ((ret.s = realpath(ARGV(char *, 0), ARGV(char *, 1))) != *(char **)t[f].data[d].ret) { This is certainly wrong, in general. You can't use equality operators to compare strings, but perhaps you're just looking for null pointers here? Also the second arg needs to be a caller-provided buffer, but part of the test structure, I think.. I'm a bit confused how this code is supposed to work. Rich