From patchwork Tue Feb 12 13:46:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 219858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A226C2C031F for ; Wed, 13 Feb 2013 00:46:40 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1361281600; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To:User-Agent:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=xJcfQucB0Tey9OKkOnKnUHYqUAQ=; b=usZF/ppKTbOvnT7 iwRok2B2DpRkDbqLzOJdH4UsMhp8nKPEo5hWF4l2geNqdq7ibKRyzlL5aGAYIput hcqUQr12kpGF3WlYSIUGdhOCf8zpHy/djOsyFHl8D9eHKFHHTs+C6RywPqZ7lf81 LNjbBEAQMsSl8tJ4spLCDpf46OtA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ULpkrBWheaqotsfHLGmXZKw2FP04v2sI+UBqVMlNZ6vG5jOo9lV8eXBpetgS3c HJVTvW+SO9/IDsKY9vxPfhwsZSyTvliCzRYugV6hjcZ82ZEpl5nRuvXbEyKSF3AP Lu9r4AOXe7F/hiIYfUpnWZQZnxYJdvveoL/FT8LmUJ7O8=; Received: (qmail 14994 invoked by alias); 12 Feb 2013 13:46:34 -0000 Received: (qmail 14986 invoked by uid 22791); 12 Feb 2013 13:46:33 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Feb 2013 13:46:24 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1CDkMmI017015 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Feb 2013 08:46:23 -0500 Received: from zalov.redhat.com (vpn1-5-178.ams2.redhat.com [10.36.5.178]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1CDkKUS031647 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 12 Feb 2013 08:46:22 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id r1CDkKiS029912; Tue, 12 Feb 2013 14:46:20 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r1CDkIqK029911; Tue, 12 Feb 2013 14:46:18 +0100 Date: Tue, 12 Feb 2013 14:46:18 +0100 From: Jakub Jelinek To: Evgeniy Stepanov Cc: Jack Howarth , Konstantin Serebryany , GCC Patches , Dodji Seketeli , Dmitry Vyukov Subject: Re: libsanitizer merge from upstream r173241 Message-ID: <20130212134618.GC4385@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20130123111352.GD7269@tucnak.redhat.com> <20130211113800.GZ4385@tucnak.redhat.com> <20130211135546.GA30679@bromo.med.uc.edu> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Tue, Feb 12, 2013 at 05:28:53PM +0400, Evgeniy Stepanov wrote: > Hey, > > seems like that last of the scanf changes are in. > We're intercepting __isoc99_*scanf irrespective of the glibc version, > because (a) it does not hurt (and with the static runtime, even > interceptor itself is thrown out by the linker), and (b) user program > and tool's runtime can be built with different libc versions. > > Thanks for the help with scanf testing, we've got much more confidence > in our implementation now. Thanks. Perhaps (completely untested) you could still disallow the GNU %as/%aS/%a[ compatibility for __isoc99_*, that way you can acurately verify even #define _XOPEN_SOURCE 700 ... float flt; int i; sscanf ("0.1234[x6]", "%a[x%d]", &flt, &i); Jakub --- sanitizer_common/sanitizer_common_interceptors.inc.jj 2013-02-12 14:34:06.000000000 +0100 +++ sanitizer_common/sanitizer_common_interceptors.inc 2013-02-12 14:40:05.486968072 +0100 @@ -150,7 +150,7 @@ INTERCEPTOR(int, prctl, int option, unsi #include "sanitizer_common_interceptors_scanf.inc" -#define VSCANF_INTERCEPTOR_IMPL(vname, ...) \ +#define VSCANF_INTERCEPTOR_IMPL(vname, allowGnuMalloc, ...) \ { \ void *ctx; \ COMMON_INTERCEPTOR_ENTER(ctx, vname, __VA_ARGS__); \ @@ -158,29 +158,29 @@ INTERCEPTOR(int, prctl, int option, unsi va_copy(aq, ap); \ int res = REAL(vname)(__VA_ARGS__); \ if (res > 0) \ - scanf_common(ctx, res, format, aq); \ + scanf_common(ctx, res, allowGnuMalloc, format, aq); \ va_end(aq); \ return res; \ } INTERCEPTOR(int, vscanf, const char *format, va_list ap) -VSCANF_INTERCEPTOR_IMPL(vscanf, format, ap) +VSCANF_INTERCEPTOR_IMPL(vscanf, true, format, ap) INTERCEPTOR(int, vsscanf, const char *str, const char *format, va_list ap) -VSCANF_INTERCEPTOR_IMPL(vsscanf, str, format, ap) +VSCANF_INTERCEPTOR_IMPL(vsscanf, true, str, format, ap) INTERCEPTOR(int, vfscanf, void *stream, const char *format, va_list ap) -VSCANF_INTERCEPTOR_IMPL(vfscanf, stream, format, ap) +VSCANF_INTERCEPTOR_IMPL(vfscanf, true, stream, format, ap) INTERCEPTOR(int, __isoc99_vscanf, const char *format, va_list ap) -VSCANF_INTERCEPTOR_IMPL(__isoc99_vscanf, format, ap) +VSCANF_INTERCEPTOR_IMPL(__isoc99_vscanf, false, format, ap) INTERCEPTOR(int, __isoc99_vsscanf, const char *str, const char *format, va_list ap) -VSCANF_INTERCEPTOR_IMPL(__isoc99_vsscanf, str, format, ap) +VSCANF_INTERCEPTOR_IMPL(__isoc99_vsscanf, false, str, format, ap) INTERCEPTOR(int, __isoc99_vfscanf, void *stream, const char *format, va_list ap) -VSCANF_INTERCEPTOR_IMPL(__isoc99_vfscanf, stream, format, ap) +VSCANF_INTERCEPTOR_IMPL(__isoc99_vfscanf, false, stream, format, ap) #define SCANF_INTERCEPTOR_IMPL(name, vname, ...) \ { \ --- sanitizer_common/sanitizer_common_interceptors_scanf.inc.jj 2013-02-11 16:56:09.000000000 +0100 +++ sanitizer_common/sanitizer_common_interceptors_scanf.inc 2013-02-12 14:37:46.948784135 +0100 @@ -39,7 +39,8 @@ static bool char_is_one_of(char c, const // returned in dir. This function returns the pointer to the first // unprocessed character, or 0 in case of error. // In case of the end-of-string, a pointer to the closing \0 is returned. -static const char *scanf_parse_next(const char *p, ScanfDirective *dir) { +static const char *scanf_parse_next(const char *p, bool allowGnuMalloc, + ScanfDirective *dir) { internal_memset(dir, 0, sizeof(*dir)); dir->argIdx = -1; @@ -121,7 +122,8 @@ static const char *scanf_parse_next(cons // This is unfortunately ambiguous between old GNU extension // of %as, %aS and %a[...] and newer POSIX %a followed by // letters s, S or [. - if (dir->convSpecifier == 'a' && !dir->lengthModifier[0]) { + if (dir->convSpecifier == 'a' && !dir->lengthModifier[0] + && allowGnuMalloc) { if (*p == 's' || *p == 'S') { dir->maybeGnuMalloc = true; ++p; @@ -271,14 +273,14 @@ static int scanf_get_store_size(ScanfDir // Common part of *scanf interceptors. // Process format string and va_list, and report all store ranges. // Stops when "consuming" n_inputs input items. -static void scanf_common(void *ctx, int n_inputs, const char *format, - va_list aq) { +static void scanf_common(void *ctx, int n_inputs, bool allowGnuMalloc, + const char *format, va_list aq) { CHECK_GT(n_inputs, 0); const char *p = format; while (*p && n_inputs) { ScanfDirective dir; - p = scanf_parse_next(p, &dir); + p = scanf_parse_next(p, allowGnuMalloc, &dir); if (!p) break; if (dir.convSpecifier == 0) {