Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3484886pxv; Mon, 19 Jul 2021 00:58:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxFd8IekUsSUV56bWgkQjhwuLHNsL70gPT0qDuJwWaHmpjx/tQkJ5aRqVSgIXUamFX90uK X-Received: by 2002:a17:906:d045:: with SMTP id bo5mr26220644ejb.461.1626681518016; Mon, 19 Jul 2021 00:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626681518; cv=none; d=google.com; s=arc-20160816; b=zD0mTTTl8l97dpFK4ybLfAGfwbos6SU8N1E/Ddd6LNyx2zI3e7KtiK6AvHzAoznhqS +SJRoCOV2IXe+7Jf5V4P29hCbkJe+W3XOturDgQyGKGngj8LEdk/xyZ6oOaEx5XpxfwL LU59gSdoTKp+nk8QBbyI1WRpmsXWdJWfjqg0DPaHvVF+7OuSttqYQmxzcJZEhLCeKyvk uPv3Uk0a96XqHdONV/cg0W3z8jgiWpssXBx7Eq4XBTvJgXchM5OujGbsmGNhg/RBkMKy arFJJqoa1PYb6jF3tP4yYIQDfP6mj9U0V5M6Ro096Kmi0ycsnEtwzYR6iS6pIiZC/yT5 dj2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=UFrHGkePZup1taj30Rt41mFp0n9XCiwOIs/xt1tbnaw=; b=aJcSiqiAzTxF7S7FCR7XBrykvFBRY3SB0WR7M658OorW9/B2cFwv0UoQqSNFzbzM4n uyCUi61a89VtKxXT7fp7gz8uPPPP3GyI6v+PvCm/qkAxBduD5eudVH/yUOdt90lc1+7D e9kUYeZbJ24L4NT6Mm8JSmqL5CqZEnvs9l+aYvdvwZkjO050k78yQbO31KBNYpwuNJYC 5ej+A2eINTmVvEiifZWjMWTjmmZKpBWcEyT44SFforpMW6VIFVt8Hbgg3jVWW8eG4Y6F XSPZgSBMAqHUFqoCfz6MjPHbLynlgUVignDLahUAI7j6F7eHi2byVy7l8lmeib8ApR3g AELg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si20174834eju.362.2021.07.19.00.58.15; Mon, 19 Jul 2021 00:58:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234943AbhGSH4y (ORCPT + 99 others); Mon, 19 Jul 2021 03:56:54 -0400 Received: from mail-ua1-f54.google.com ([209.85.222.54]:35698 "EHLO mail-ua1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235180AbhGSH4q (ORCPT ); Mon, 19 Jul 2021 03:56:46 -0400 Received: by mail-ua1-f54.google.com with SMTP id n61so6493301uan.2; Mon, 19 Jul 2021 00:53:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UFrHGkePZup1taj30Rt41mFp0n9XCiwOIs/xt1tbnaw=; b=ILbqZWvTJ4tnouXLPQmgYQhcoUF9/+cAIYgUjJbF0zcCAcWJcwAEcIRXWs/zvynuzZ HJx2hYBqI8YtidL3XlaDBILFYUzzS+p2boNhgF2Hr3xaav2OLSLq/PWdHkUWTD1ULZW8 2YxcM1NZJzJDLarp7S1Ut2q5RqcOD8N3U6RK+5ZB61eY2cPwTPy5zlY9iPgc7zXmh/Y9 rtRBw15hG5TrG2S2zHOF/F5tr7hMyX/u94wN8ZIPS50+TXgiJ3dthcDb12FoV7Dh4I2n RWoDy0eP0qZ/8keeFIwwhl4jYxPuaktVxl0UZ8WDJzWztYImUUEn1HcU4GUlw5LaIyYn y7AQ== X-Gm-Message-State: AOAM5324RULE5Dm+9m9/N9mPwofzWP5ZBnCsVaaIMBVP0r7c8zV4IPSc si+ocUseyrm5QXSZNrLWNXIcIE7Op5C5mk4AVYw= X-Received: by 2002:a9f:3f0d:: with SMTP id h13mr24866271uaj.100.1626681220672; Mon, 19 Jul 2021 00:53:40 -0700 (PDT) MIME-Version: 1.0 References: <20210718133920.15825-1-len.baker@gmx.com> In-Reply-To: From: Geert Uytterhoeven Date: Mon, 19 Jul 2021 09:53:29 +0200 Message-ID: Subject: Re: [PATCH] staging/fbtft: Remove all strcpy() uses To: Andy Shevchenko Cc: Len Baker , Greg Kroah-Hartman , Andy Shevchenko , Phil Reid , dri-devel , "open list:FRAMEBUFFER LAYER" , linux-staging@lists.linux.dev, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jul 18, 2021 at 9:43 PM Andy Shevchenko wrote: > On Sun, Jul 18, 2021 at 4:43 PM Len Baker wrote: > > strcpy() performs no bounds checking on the destination buffer. This > > could result in linear overflows beyond the end of the buffer, leading > > to all kinds of misbehaviors. The safe replacement is strscpy() but in > > this case it is simpler to add NULL to the first position since we want "NULL" is a pointer value, "NUL" is the character with value zero. > > to empty the string. > > > This is a previous step in the path to remove the strcpy() function. > > Any document behind this (something to read on the site(s) more or > less affiliated with what is going to happen in the kernel) to read > background? > > ... > > > case -1: > > i++; > > /* make debug message */ > > - strcpy(msg, ""); While this strcpy() is provably safe at compile-time, and will probably be replaced by an assignment to zero by the compiler... > > + msg[0] = 0; > > Strictly speaking it should be '\0'. > > > j = i + 1; > > while (par->init_sequence[j] >= 0) { > > sprintf(str, "0x%02X ", par->init_sequence[j]); ... the real danger is the strcat(msg, str); on the next line. Fortunately this whole debug printing block (including the strcpy) can (and should) be rewritten to just use "%*ph". Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds