From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, RCVD_IN_DNSWL_NONE autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 29560 invoked from network); 18 Dec 2020 11:34:53 -0000 Received: from ewsd.inri.net (107.191.116.128) by inbox.vuxu.org with ESMTPUTF8; 18 Dec 2020 11:34:53 -0000 Received: from smtp26.services.sfr.fr ([93.17.128.193]) by ewsd; Fri Dec 18 06:30:01 -0500 2020 Received: from cauchy.polynum.local (89.121.198.77.rev.sfr.net [77.198.121.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by msfrf2607.sfr.fr (SMTP Server) with ESMTPS id 91E911C00042B for <9front@9front.org>; Fri, 18 Dec 2020 12:29:45 +0100 (CET) X-mail-filterd: 1.0.0 X-sfr-mailing: LEGIT X-sfr-spamrating: 40 X-sfr-spam: not-spam DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=polynum.com; s=202006; t=1608290985; h=Date:From:To:Subject:References:In-Reply-To; bh=Mnokqc/FCs0o mnnE/r1aHMV7I1rmRPZo3lwlPdsggL0=; b=ekN8CS2FK8qmbdLCD4spta0/8hQ1tzBhB1sWGICA U41MXYpiwD7DWLyZhH+GBNMoC9G12/AcpjIVwtYpN7JZrDXNRHH6Vw7ktRZp2CkbtfmkUlh/yYxn nlwCbB03m887aQda2K7xC6BnbR8hBufOqrexsyyhFcdNORS+yNRfyBxekv9oFyRR6wmgxb2iby1b yS27BUb1Gqv0qmTjSNWJ8LXU49fHQtwxpzUoNX/bAfdA2ffK0LlqtHZ56yrPCLJ+idtZJ9Zcpk28 1ZUOH0K8tCNgO6lJxIdDlmzg/EE3xe0BQt/v15G4OZp0VdmQCLDMyCMWzGyeatqiWkWVDt8j8Q== ; Received: from cauchy.polynum.local (89.121.198.77.rev.sfr.net [77.198.121.89]) by msfrf2607.sfr.fr (SMTP Server) with ESMTP id 6E3CF1C000425 for <9front@9front.org>; Fri, 18 Dec 2020 12:29:45 +0100 (CET) Received: from cauchy.polynum.local (89.121.198.77.rev.sfr.net [77.198.121.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by msfrf2607.sfr.fr (SMTP Server) with ESMTPS for <9front@9front.org>; Fri, 18 Dec 2020 12:29:45 +0100 (CET) Received: from cauchy.polynum.local (localhost [127.0.0.1]) by cauchy.polynum.local (8.15.2/8.15.2) with ESMTPS id 0BIBTEHN001240 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for <9front@9front.org>; Fri, 18 Dec 2020 12:29:15 +0100 (CET) Received: (from tlaronde@localhost) by cauchy.polynum.local (8.15.2/8.14.9/Submit) id 0BIBTE0B001206 for 9front@9front.org; Fri, 18 Dec 2020 12:29:14 +0100 (CET) X-Authentication-Warning: cauchy.polynum.local: tlaronde set sender to thierry.laronde@sfr.fr using -f Date: Fri, 18 Dec 2020 12:29:14 +0100 From: tlaronde@polynum.com To: 9front@9front.org Message-ID: <20201218112914.GA717@polynum.com> References: <54874114B98195307A5780FB707F9115@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54874114B98195307A5780FB707F9115@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: proven progressive SOAP map/reduce NoSQL general-purpose solution Subject: Re: [9front] strndup should use strnlen and memcpy Reply-To: 9front@9front.org Precedence: bulk On Fri, Dec 18, 2020 at 11:31:22AM +0100, Sigrid Solveig HaflC-nudC3ttir wrote: > > Open Group does not specify if arg1 should be null terminated or not. > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/strdup.html > > "Applications should not assume that strndup() will allocate ( size + 1) > bytes when strlen(s) is smaller than size." > > Pretty sure this means it's supposed to be null-terminated, or > otherwise it wouldn't mention the "dangerous" strlen right there. As I read it---but I'm not an english native speaker---this only means that one shall not infer that the allocation will be len + 1 (since if the string is shorter, it will be less). This does not say anything about a terminating '\0' and this is precisely the purpose to copy some amount of chars in a null terminated array of chars (the dup will be null terminated; it is not a requirement of the chars array duplicated). the name could have been mem2nstr (fixed maximum size length str as a result, not as an argument). -- Thierry Laronde http://www.kergis.com/ http://kertex.kergis.com/ http://www.sbfa.fr/ Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C