From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1525 invoked by alias); 30 Aug 2014 03:53:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 1514 invoked by uid 89); 30 Aug 2014 03:53:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f181.google.com Received: from mail-pd0-f181.google.com (HELO mail-pd0-f181.google.com) (209.85.192.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 30 Aug 2014 03:53:48 +0000 Received: by mail-pd0-f181.google.com with SMTP id fp1so1729262pdb.40 for ; Fri, 29 Aug 2014 20:53:46 -0700 (PDT) X-Received: by 10.70.134.165 with SMTP id pl5mr20646261pdb.20.1409370826160; Fri, 29 Aug 2014 20:53:46 -0700 (PDT) Received: from ShengShiZhuChengdeMacBook-Pro.local ([219.143.94.131]) by mx.google.com with ESMTPSA id ur5sm5492922pac.46.2014.08.29.20.53.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Aug 2014 20:53:45 -0700 (PDT) Message-ID: <54014BEE.5020408@gmail.com> Date: Sat, 30 Aug 2014 03:53:00 -0000 From: Chen Gang User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: Konstantin Serebryany CC: Jakub Jelinek , Dodji Seketeli , Kostya Serebryany , Dmitry Vyukov , gcc-patches List , Jeff Law Subject: Re: [PATCH] libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc: Avoid writing '\0' out of string's border References: <53FE5EF6.5030003@gmail.com> <53FE62A0.606@gmail.com> In-Reply-To: <53FE62A0.606@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2014-08/txt/msg02682.txt.bz2 On 8/28/14 6:58, Chen Gang wrote: > On 08/28/2014 06:51 AM, Konstantin Serebryany wrote: >> But, what makes you think there is a bug here? >> The comment in sanitizer_common/sanitizer_common.h says: >> // name should have space for at least max_len+1 bytes. >> > > Oh, really, but for me, I still prefer to let max_len as all real buffer > length which like common sense (especially for extern functions). > > If this extern function is not real used, at present (but will be used > next), for me, I still want to improve it (about max_len). In the current gcc source code, it is not used, but I guess, it may be used, next. Theoretically, we can treate all extern functions as API, which need be more careful about its declarations (include parameters definition), or may borther many callers: - If caller has duty to be sure of '\0' terminated (e.g. strncpy), callee need not care about it. For our case, need remove "name[max_len] = 0;". - If callee has duty to be sure of '\0' terminated (snprintf, gets), caller need not care about it. For our case, need use "max_len - 1" instead of "max_len". For me, the extern function is neccesary to be improved in time (before it is used by others). Or as an API, it is hard to be changed again. Thanks. -- Chen Gang Open, share, and attitude like air, water, and life which God blessed