From stdcxx-dev-return-1747-apmail-incubator-stdcxx-dev-archive=incubator.apache.org@incubator.apache.org Fri Jul 14 15:28:27 2006 Return-Path: Delivered-To: apmail-incubator-stdcxx-dev-archive@www.apache.org Received: (qmail 71727 invoked from network); 14 Jul 2006 15:28:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 14 Jul 2006 15:28:27 -0000 Received: (qmail 81737 invoked by uid 500); 14 Jul 2006 15:28:27 -0000 Delivered-To: apmail-incubator-stdcxx-dev-archive@incubator.apache.org Received: (qmail 81723 invoked by uid 500); 14 Jul 2006 15:28:26 -0000 Mailing-List: contact stdcxx-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-dev@incubator.apache.org Received: (qmail 81712 invoked by uid 99); 14 Jul 2006 15:28:26 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jul 2006 08:28:26 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [212.82.213.172] (HELO exkiv.kyiv.vdiweb.com) (212.82.213.172) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jul 2006 08:28:25 -0700 Received: from [10.11.37.44] ([10.11.37.44]) by exkiv.kyiv.vdiweb.com with Microsoft SMTPSVC(6.0.3790.1830); Fri, 14 Jul 2006 18:28:20 +0300 Message-ID: <44B7B814.8020104@kyiv.vdiweb.com> Date: Fri, 14 Jul 2006 18:28:20 +0300 From: Farid Zaripov User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: stdcxx-dev@incubator.apache.org Subject: RE: Environment for the test of the string functions memory overrun with example Content-Type: multipart/mixed; boundary="------------010601050300050806010501" X-OriginalArrivalTime: 14 Jul 2006 15:28:20.0295 (UTC) FILETIME=[23034570:01C6A75A] X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------010601050300050806010501 Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit > -----Original Message----- > From: Martin Sebor [mailto:sebor@roguewave.com] > Sent: Friday, July 14, 2006 12:07 AM > To: stdcxx-dev@incubator.apache.org > Subject: Re: Environment for the test of the string functions > memory overrun with example > [...] > > Okay, this version is closer to what I have in mind :) There > are a few minor tweaks that I would still make but I think > it's ready to commit as is (please go ahead and have Anton do > it). We can make the tweaks later (we will also need a test > to exercise this). [...] I have updated the rw_alloc.h and alloc.cpp according to your comments. Anton commited this version (http://svn.apache.org/viewvc?rev=421918&view=rev). Also I wrote the test to exercise the rw_alloc() function (tests/self/0.alloc.cpp). The test is attached. Farid. --------------010601050300050806010501 Content-Type: text/plain; name="0.alloc.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0.alloc.cpp" /************************************************************************ * * 0.alloc.cpp - test exercising the rw_alloc() and rw_free() functions * * $Id: 0.alloc.cpp * ************************************************************************ * * Copyright 2006 The Apache Software Foundation or its licensors, * as applicable. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * **************************************************************************/ #include // for signal #include // for setjmp, longjmp #include // for rw_alloc, rw_free #include // for rw_printf #include #ifdef __CYGWIN__ // use the Windows API on Cygwin # define _WIN32 #endif static jmp_buf mark; static void sig_handler (int) { longjmp (mark, -1); } #ifdef sigsetjmp #define SETJMP(env) sigsetjmp (env, 1) #else #define SETJMP(env) setjmp (env) #endif #define BEGIN_TEST_OVERRUN() \ signal (SIGSEGV, sig_handler), \ (0 == SETJMP (mark)) struct TestCase { size_t size_; int index_; int prot_; const char* file_; int line_; }; void test (const TestCase& tcase) { if (void* buf = rw_alloc (tcase.size_, tcase.prot_)) { char* str = _RWSTD_STATIC_CAST (char*, buf); bool protbelow = 0 != (tcase.prot_ & RW_PROT_BELOW); bool canread = (tcase.prot_ & #if defined (_WIN32) || defined (_WIN64) (RW_PROT_READ | RW_PROT_WRITE | RW_PROT_EXEC)) #else (RW_PROT_READ | RW_PROT_EXEC)) #endif && ( (protbelow && 0 <= tcase.index_) || (!protbelow && tcase.index_ < int (tcase.size_)) ); bool canwrite = (tcase.prot_ & RW_PROT_WRITE) && ( (protbelow && 0 <= tcase.index_) || (!protbelow && tcase.index_ < int (tcase.size_)) ); char c = 'a'; if (BEGIN_TEST_OVERRUN ()) { c = str[tcase.index_]; rw_assert (canread, tcase.file_, tcase.line_, "expected no read access, got read access"); } else rw_assert (!canread, tcase.file_, tcase.line_, "expected read access, got no read access"); if (BEGIN_TEST_OVERRUN ()) { str[tcase.index_] = c; rw_assert (canwrite, tcase.file_, tcase.line_, "expected no write access, got write access"); } else rw_assert (!canwrite, tcase.file_, tcase.line_, "expected write access, got no write access"); rw_free (buf); } } static int run_test (int, char**) { const size_t BUF_SIZE = 10; static const TestCase tcases[] = { #ifdef TEST #undef TEST #endif #define TEST(size, index, prot) \ { size, index, prot, __FILE__, __LINE__ } TEST(BUF_SIZE, -1, RW_PROT_NONE), TEST(BUF_SIZE, -1, RW_PROT_READ), TEST(BUF_SIZE, -1, RW_PROT_WRITE), TEST(BUF_SIZE, -1, RW_PROT_EXEC), TEST(BUF_SIZE, -1, RW_PROT_NONE | RW_PROT_BELOW), TEST(BUF_SIZE, -1, RW_PROT_READ | RW_PROT_BELOW), TEST(BUF_SIZE, -1, RW_PROT_WRITE | RW_PROT_BELOW), TEST(BUF_SIZE, -1, RW_PROT_EXEC | RW_PROT_BELOW), TEST(BUF_SIZE, 0, RW_PROT_NONE), TEST(BUF_SIZE, 0, RW_PROT_READ), TEST(BUF_SIZE, 0, RW_PROT_WRITE), TEST(BUF_SIZE, 0, RW_PROT_EXEC), TEST(BUF_SIZE, 0, RW_PROT_NONE | RW_PROT_BELOW), TEST(BUF_SIZE, 0, RW_PROT_READ | RW_PROT_BELOW), TEST(BUF_SIZE, 0, RW_PROT_WRITE | RW_PROT_BELOW), TEST(BUF_SIZE, 0, RW_PROT_EXEC | RW_PROT_BELOW), TEST(BUF_SIZE, BUF_SIZE, RW_PROT_NONE | RW_PROT_BELOW), TEST(BUF_SIZE, BUF_SIZE, RW_PROT_READ | RW_PROT_BELOW), TEST(BUF_SIZE, BUF_SIZE, RW_PROT_WRITE | RW_PROT_BELOW), TEST(BUF_SIZE, BUF_SIZE, RW_PROT_EXEC | RW_PROT_BELOW), TEST(BUF_SIZE, BUF_SIZE, RW_PROT_NONE), TEST(BUF_SIZE, BUF_SIZE, RW_PROT_READ), TEST(BUF_SIZE, BUF_SIZE, RW_PROT_WRITE), TEST(BUF_SIZE, BUF_SIZE, RW_PROT_EXEC), TEST(BUF_SIZE, BUF_SIZE - 1, RW_PROT_NONE | RW_PROT_BELOW), TEST(BUF_SIZE, BUF_SIZE - 1, RW_PROT_READ | RW_PROT_BELOW), TEST(BUF_SIZE, BUF_SIZE - 1, RW_PROT_WRITE | RW_PROT_BELOW), TEST(BUF_SIZE, BUF_SIZE - 1, RW_PROT_EXEC | RW_PROT_BELOW), TEST(BUF_SIZE, BUF_SIZE - 1, RW_PROT_NONE), TEST(BUF_SIZE, BUF_SIZE - 1, RW_PROT_READ), TEST(BUF_SIZE, BUF_SIZE - 1, RW_PROT_WRITE), TEST(BUF_SIZE, BUF_SIZE - 1, RW_PROT_EXEC) }; for (size_t i = 0; i < sizeof (tcases) / sizeof (tcases[0]); ++i) test (tcases [i]); return 0; } /***********************************************************************/ int main (int argc, char *argv[]) { return rw_test (argc, argv, __FILE__, "", 0, run_test, "", (void*)0 /* sentinel */); } --------------010601050300050806010501--