Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9757039ybi; Wed, 24 Jul 2019 09:24:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8munqLKq7J+om0FSSzrJcgTttM7ZBIPhSvdXtdYFK5jEzPNyiyDEU6UyFbKxmP1XTZ4t3 X-Received: by 2002:a17:902:f01:: with SMTP id 1mr86177895ply.170.1563985486005; Wed, 24 Jul 2019 09:24:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563985485; cv=none; d=google.com; s=arc-20160816; b=I5098wfxj8cLQhBtUM5T/lWyVHDBABL2yR7NrnRrBOqlpyDjWeNuOpjECeTPoxLDee mwHWj4pXOO4uru5UH5lx+Iju2HGflameiOtvdx8308v3zeoMoEVcYa9r9OHNgY4DRoc8 hmC3M4XHaSNc9dk/kMYKoGe29rSHYMYOdk1P1HLgtZXTzbNXEJzftb2Z+ro5m+2ZiKC3 P6JzA5OKuCd6hTMuhTFoxsjfVICWDMU8FB+Jlqjbi+2fOCQ98oZhaWbQHfhN8lTZVnz1 xEOeikA/N55kDlrwW2me0a2vnRxIdoPeGe9FRxFXvlCzhxNtMDDPnr/rJbUFh8Hg1cH1 6i4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=f4suZrpfhVME9PStBS3l8/qYNB52LjXte4Jp7QV1fJc=; b=nJzPXvzDo1ljzwSbtzbr5UvQsuUxm/QfSDj+kEXlzx9QtevJcNV8KI/ffdu6pasRVR unKQWzC2pfPvUfzImqPN+fZ8B+QQwHm5HasnwvRP57H/YFn6VULBaYDDhu1/dWQmwzIS oCLGgLiP2V/7Vcs4e+pcJADjhg6N9JKzpafvIb4mEl9M1GgfkADD4oB1rI+KxSuTXdMy vzzDk/eqqHsuaSpFkqxs7cbh+LGnXFTsyLmUYlZQmM3rijrbJoUzdp65XwOXbemDmO3S AifDAY036Ee6JekFXSrxCSWQLViRbQj7kZ87ZuiQHYWsDV/3TCjZkJ6hL4hf9BXg0LKx UkbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=P1hm04nm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si14265357plh.265.2019.07.24.09.24.30; Wed, 24 Jul 2019 09:24:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=P1hm04nm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387470AbfGXNJP (ORCPT + 99 others); Wed, 24 Jul 2019 09:09:15 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41039 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726535AbfGXNJO (ORCPT ); Wed, 24 Jul 2019 09:09:14 -0400 Received: by mail-lj1-f196.google.com with SMTP id d24so44428063ljg.8 for ; Wed, 24 Jul 2019 06:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=f4suZrpfhVME9PStBS3l8/qYNB52LjXte4Jp7QV1fJc=; b=P1hm04nmq8167DSE3iTDmBtlSkwmwS0C9IQYXgXAr3bOqgsitm4JZyJpEwjECFSJ3r hVs+wZSxh9IimkkFqfvll8rE1TX6cXYyb3yJrOQ4slWIUZeOdB5qdSQVrQjt4D7xVDlu rrCg74BJef1BmvhakY4s2UB0xlON8LZ++gDkQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=f4suZrpfhVME9PStBS3l8/qYNB52LjXte4Jp7QV1fJc=; b=Fcey8NnNSRxtqHccNEgra6tUAcky5004lyw5xj8AANSvqCy5zehUgz1/zRxIHg7tND 8EToOR+7GiFeBPtE613esDcq2qRWt9DPYdrkv6EZKPsyY3PBfjaDfUri6ONMlIzBkgJn FezdZvalNcLVwgkVNgJhnqhYBL7oQIe8Y3GwbanSxF73jN3Xav7/XzMPUt85XuMs9ICt nle1iYWhEGg1/S/NZnKLSUdNFZDR9ACP8/1o6UPl3+V4YvtsPdEnvFpki67VMtGXtPVl BSnkHNn8HCQIsxaUnf9JAGkxMVBP8cjIeDWVR7bz/pwZI+UKVzzl5Uzqu1bnfZqr+Gza EZIQ== X-Gm-Message-State: APjAAAUXHdy+4PnN6NdZFG0vlUZiOr8+ypu+ZNHqaRYY3i8gH4wlSDJy X0lIbH2KzmmRPgCAvpIZOW3Frpzw4mBDVQ== X-Received: by 2002:a2e:93c5:: with SMTP id p5mr41945289ljh.79.1563973752416; Wed, 24 Jul 2019 06:09:12 -0700 (PDT) Received: from [172.16.11.28] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id u13sm7095045lfl.61.2019.07.24.06.09.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jul 2019 06:09:11 -0700 (PDT) Subject: Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms To: Yann Droneaud , David Laight , Joe Perches , Linus Torvalds , "linux-kernel@vger.kernel.org" Cc: Jonathan Corbet , Stephen Kitt , Kees Cook , Nitin Gote , "jannh@google.com" , "kernel-hardening@lists.openwall.com" , Andrew Morton References: <7ab8957eaf9b0931a59eff6e2bd8c5169f2f6c41.1563841972.git.joe@perches.com> <5ffdbf4f87054b47a2daf23a6afabecf@AcuMS.aculab.com> From: Rasmus Villemoes Message-ID: <396d1eed-8edf-aa77-110b-c50ead3a5fd5@rasmusvillemoes.dk> Date: Wed, 24 Jul 2019 15:09:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/07/2019 14.05, Yann Droneaud wrote: > Hi, > > Beware that snprintf(), per C standard, is supposed to return the > length of the formatted string, regarless of the size of the > destination buffer. > > So encouraging developper to write something like code below because > snprintf() in kernel behave in a non-standard way, The kernel's snprintf() does not behave in a non-standard way, at least not with respect to its return value. It doesn't support %n or floating point, of course, and there are some quirks regarding precision (see lib/test_printf.c for details). There's the non-standard scnprintf() for getting the length of the formatted string, which can safely be used in an append loop. Or one can use the seq_buf API. Rasmus