Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3541756ybi; Mon, 29 Jul 2019 08:18:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYDQflpqJz0SaoTbQOKiI9obEf/tkxtTqtYAi8jSeJ1hW5yOfWddcXkuK65HmJZXp6G499 X-Received: by 2002:a62:15c3:: with SMTP id 186mr38514653pfv.141.1564413490705; Mon, 29 Jul 2019 08:18:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564413490; cv=none; d=google.com; s=arc-20160816; b=sYocdenV9I6R6hgyF/cHQYUZnbNkb/Dl/GqJ0rVlfDBPvzobIdD0ifJMH6X0oADNK7 aV1vXkvFP/m4aeN/xdRTM+FL4R8BcHv0t81Y6JUgOwZsWBIMKtjQA8OuhEyqwHeImdsA 89MtAqngKVCi/yyAnj0PN8iUKc3wC94k+Vf95Si4hgfhzvDy4zJbVOHNnQiaO7Pobfsf XEJColygN79DZcq9tSdOxTJKkFapXtg2+Hw5Dv/P94iPQIMQSQgPF8lnvgrpRAgYw1nr UElkEgnZbEJJATTdRqUGRmN6bxbRaFV0OOgDzXezORYxsbidKlTQfQBCIKOG6ZpLTQWx 8dXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=IZw5zJlUaHZqjTi8v7H9aY2VgBMCyLLOX5E3euuUe8A=; b=x/n35QJkag2uxMz+YxOdSHqHg9/bxgovAns0Wx9FKW1wNcmcdEiDr/XB8PJmB6inGt 3i6caKA2SzHjQInt1L35FftBDt/N0UAJCglbxe6tT+xxWpvsToYDGTVROEgflhh4RRpr TIN7dZjz6dgBKhCRy6fq5Pvw5QXMFDoN171r9deNn7HKUEAPgN+uzC0kJL8zJWw9QtSe hGQK13sJPnZ2HimlfExCW3WxfVN3SaemvKvfeDPa1PrQqm+BIW3kdaBaaA5ne+nq2WBu 0MvEDxKsNgSwCozUw2sUSkHW35cpAYHqk4XA5e0yU/MOq4YvV/jQRRT+QPO2fG0lfcWQ BUoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=A+Q4hSFe; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o70si24897457pgo.280.2019.07.29.08.17.54; Mon, 29 Jul 2019 08:18:10 -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=fail header.i=@gmail.com header.s=20161025 header.b=A+Q4hSFe; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728827AbfG2PPc (ORCPT + 99 others); Mon, 29 Jul 2019 11:15:32 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36485 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728023AbfG2PPc (ORCPT ); Mon, 29 Jul 2019 11:15:32 -0400 Received: by mail-pg1-f193.google.com with SMTP id l21so28418694pgm.3 for ; Mon, 29 Jul 2019 08:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IZw5zJlUaHZqjTi8v7H9aY2VgBMCyLLOX5E3euuUe8A=; b=A+Q4hSFeN/v8VhH2QhtaBTcxMp1KevW34tUAFJnIfjOabcdYI5JZPWNZt4C1xVYR5b Q+8C1vWoO0X8bW4h7I8bb4nvqr5DDBnXps/erEkKudRObCxl3XDdS/9yRgDVIN5dA7P2 JkoPYysUudx9eQZrRiWKggKgdWPt4Cz46niYOSdH4FYIMVF67rLEj32mxvEGyXP9xNqo ARVQdvqpMbyKNxS9ttPjUgQVya65z00IKE2HqH89cbIxi2l6jAM3AgLGauFnVJOgkQ/t VdP7YdL2JaYvUGPBx7dsPNyDzbEtC48OS8FxdedCO0za6CCsqF+D+J/yZFWSbRAtrCzh cc1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IZw5zJlUaHZqjTi8v7H9aY2VgBMCyLLOX5E3euuUe8A=; b=Togf3AIa2LjUrXrxAiXF0s+mX2zR3rSEVjc5SJMykmIWLY4ezkPtJJo8KJLBjP9ayk h13bjvG+oiurmOyiYSmWjIUavAJ58iX1vi8obQ+7/xdOKgbLfiWjQWI+CzaWM9dwt+Ns 9zeASzaYRQb49FbLRNcXJnm25Ocjz58Je3nQXvmSKm2N2ajsy3+B1tZug5XCRZouxy6x Q0fcnHFHw/pgZ41yXrjCCfzcXY2W3LQpljsyOqQSunPlnFuokZC7nA349KgbZrIiF/e4 jvQrTKUatkN1yG5NSBLl2nWbBAObAaBZqWIJRdlmJ2xsAwxsNMuKiBBenEtY3YY/j+0v jkRw== X-Gm-Message-State: APjAAAVSLu0K0L3NTnpTTOnlWH6+TkqvNGM3/IrEUsY/Bk8LPotHgcIv vNg2EHK9RDk+Nqz0v6Id2gMadzrwQlk= X-Received: by 2002:a65:5c4b:: with SMTP id v11mr62169605pgr.62.1564413331402; Mon, 29 Jul 2019 08:15:31 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id y194sm29691319pfg.116.2019.07.29.08.15.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 08:15:30 -0700 (PDT) From: Chuhong Yuan Cc: linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH 11/12] userns: Replace strncmp with str_has_prefix Date: Mon, 29 Jul 2019 23:15:27 +0800 Message-Id: <20190729151527.9822-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org strncmp(str, const, len) is error-prone. We had better use newly introduced str_has_prefix() instead of it. Signed-off-by: Chuhong Yuan --- kernel/user_namespace.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 8eadadc478f9..4a06ba563531 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -1153,11 +1153,10 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf, /* What is being requested? */ ret = -EINVAL; - if (strncmp(pos, "allow", 5) == 0) { + if (str_has_prefix(pos, "allow")) { pos += 5; setgroups_allowed = true; - } - else if (strncmp(pos, "deny", 4) == 0) { + } else if (str_has_prefix(pos, "deny")) { pos += 4; setgroups_allowed = false; } -- 2.20.1