From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08169C43387 for ; Sat, 22 Dec 2018 17:47:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CCADF20578 for ; Sat, 22 Dec 2018 17:47:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391606AbeLVRrP (ORCPT ); Sat, 22 Dec 2018 12:47:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:34146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387658AbeLVRrN (ORCPT ); Sat, 22 Dec 2018 12:47:13 -0500 Received: from vmware.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 10A8A21B22; Sat, 22 Dec 2018 15:12:46 +0000 (UTC) Date: Sat, 22 Dec 2018 10:12:44 -0500 From: Steven Rostedt To: Namhyung Kim Cc: LKML , Linus Torvalds , Ingo Molnar , Andrew Morton , Greg Kroah-Hartman , Joe Perches , Masami Hiramatsu , Tom Zanussi , Andreas Schwab , kernel-team@lge.com Subject: Re: [PATCH v4] string.h: Add str_has_prefix() helper function Message-ID: <20181222101244.7da017c9@vmware.local.home> In-Reply-To: <20181222142411.GA10058@danjae.aot.lge.com> References: <20181221231924.4583e90b@vmware.local.home> <20181222093346.GB7610@danjae.aot.lge.com> <20181222072404.27a7e9a3@vmware.local.home> <20181222142411.GA10058@danjae.aot.lge.com> X-Mailer: Claws Mail 3.15.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 22 Dec 2018 23:24:11 +0900 Namhyung Kim wrote: > > No, because we don't know the length of str. > > > > > > [ str = "h\0[bad memory]" ] > > > > > > str_has_prefix(str, "TEST THIS BIG STRING AT FRONT") > > > > > > If we use memcmp(), then we are testing way after str has ended, and > > that can cause a memory fault. > > I don't know what's the bad memory causing memory fault but anyway > memcpy() should stop at the NUL character first as it's different, no? No, that's the difference between memcpy() and strncpy(), memcpy() doesn't care about nul characters. It's copying memory not strings. -- Steve