Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp509129lqp; Mon, 10 Jun 2024 10:28:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBvXBvFhRtLSu+tJ1DOg8TpDwcXN11xQcW2ffeQiOI/N4CUfNGTTBXx+hNCVp83qmt8xqcbuWXrK3sZ4VpPFkWvd4Etpdx6yTvUl3kKA== X-Google-Smtp-Source: AGHT+IEqSIUKDD1FYRCE+CAh/IOqDkIjb2AzHEx/S6AiPD8MOy2VGHg6VT0ATBsKIuwLYnE2EDcp X-Received: by 2002:a05:6358:e498:b0:19f:4967:4e69 with SMTP id e5c5f4694b2df-19f49675388mr620714055d.30.1718040528705; Mon, 10 Jun 2024 10:28:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718040528; cv=pass; d=google.com; s=arc-20160816; b=LCeQjPk0vESVFY2gdNxrapV/A6B5ZvCaCrKAeyVEGE5sRTRhJBrKqxG5NkLsgsUGNg +pl2ZGPjWkBhEBVVtqk6eiGWsLJ9DoniFgf72d7TbZxu2WylH1KxjuuZWV04icXNmUob yT2wdpmGx9Y3aVilkY/ooTO1VysEzT0kxn8V28G8no+WaDE9Dztp/5yXuS6g+YWzZ0iN 6BCvQHk6QY+RRBaptwl6lbpqs0GegO5st1rktjoo9ZFkPlH1XTBwD/tCtc4h93VuTMyg bTjB8vYYdkPCk1bOYjPvrbLzKtUoY9XXUXod0Clf3iZnT3rAfwjWdbNcDrEeO1Bo5YWR ozmQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=7Ss+jn32vMkFORsgEtb9NzBOj1J/8gbZRcW5oNqfgF8=; fh=2Ys2f5WheAE78t0gUy+s4vZvbU0orpcIelxQynjUL40=; b=MLOROlFWcrar4AUPKste9IvvQJqlhPOQr3AY/AX2/oJYLOsQ47E8USk4mskM7d9rRA qgmmB+GglZb2bkITu9cLO4aOps4J3BcjbRKJk1SCY6+YaaoBaVgTrMlQc+yVdiv4OQ4I ldlKqgppdNvHV4DK8MhjEvwxAtUkVpXlfcXSFAWLQwUz/pIUgSoyAw8j5LHS0LRs8/Wk qY3z2k7F7Ej0npe5Ojwv6Nw1CqodPnelPJ9EiVp1RHCPHclNpws7Fhtcbgb2DNHcXmEX Q/bDnEmMjuxw5QB1YLLdOVr55dLQNPYvCAPR1tnvqav1SV2RvGN4K2TKP0aSl/FnREkU dpEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZzQrSY57; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-208651-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208651-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e69ad0bae7si4519347a12.592.2024.06.10.10.28.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 10:28:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208651-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZzQrSY57; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-208651-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208651-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4B16D280A78 for ; Mon, 10 Jun 2024 17:28:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15C47147C60; Mon, 10 Jun 2024 17:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZzQrSY57" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 400EF145FEF for ; Mon, 10 Jun 2024 17:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718040520; cv=none; b=rjjIhd78zQc75zPUiDeWQMWHsBg8yPBJyO4dpWmeBoaxyDq96HaAqN6+nLDGJrw/1eJgsy8ExtCxslDn7DMJkyadskTQfcEMPU0/xXBfdLMInB+ulsysQuV1pzQkRJhR/UuquQfEgjgH10LqR7uhv533lBAx/x5vI8rIN7Dd77M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718040520; c=relaxed/simple; bh=E9w89+B2B7+pHEOspQLd1KCD1iOqsKdjTUWoD8G4oyY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RSz9mZRrB8uHVXi1zFA8INp+7Lo2WLt3cjZUolwiHzUTm8tG0IP7239/qAx4w90JoveHeEJsZ0J26GmK37EJEOf15ljjxEs8EwvbjT+uS1Jv4gTdwj8k1+pYj5greWNtzmLDdNRb5HVjCq5crCXcoIhfVDVWpG/GeY1ZTzlrFsg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZzQrSY57; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718040517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7Ss+jn32vMkFORsgEtb9NzBOj1J/8gbZRcW5oNqfgF8=; b=ZzQrSY57HY3GQNdVyWz4DWwmQ2I/DDkfj9FWudGSciMNR2OYvXCzecxSCOX0yUWKNq1uNa QW07dqp9e/ZjUru2fmwKCStbP3/1yzsKmv7Jy22jyyaeN7OW5aa7Ha8QkXNkjki6/dzGV/ IEfQvXqPN53FsZU7jACig6c9M/cyfZY= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-274-Z9pgwgGBNoeVKBMxF7Atag-1; Mon, 10 Jun 2024 13:28:34 -0400 X-MC-Unique: Z9pgwgGBNoeVKBMxF7Atag-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 43AC219560B4; Mon, 10 Jun 2024 17:28:33 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (bmarzins-01.fast.eng.rdu2.dc.redhat.com [10.6.23.12]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6F6F619560AB; Mon, 10 Jun 2024 17:28:32 +0000 (UTC) Received: from bmarzins-01.fast.eng.rdu2.dc.redhat.com (localhost [127.0.0.1]) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.1) with ESMTPS id 45AHSVBf801304 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 10 Jun 2024 13:28:31 -0400 Received: (from bmarzins@localhost) by bmarzins-01.fast.eng.rdu2.dc.redhat.com (8.17.2/8.17.2/Submit) id 45AHSUBI801303; Mon, 10 Jun 2024 13:28:30 -0400 Date: Mon, 10 Jun 2024 13:28:30 -0400 From: Benjamin Marzinski To: Abhinav Jain Cc: agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com, dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, javier.carrasco.cruz@gmail.com Subject: Re: [PATCH] dm: Add support for escaped characters in str_field_delimit() Message-ID: References: <20240609141721.52344-1-jain.abhinav177@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 On Mon, Jun 10, 2024 at 01:11:40PM -0400, Benjamin Marzinski wrote: > On Sun, Jun 09, 2024 at 02:17:21PM +0000, Abhinav Jain wrote: > > Add a new variable for escaped characters. > > > > If an escaped character (\) is found before the separator, and if the > > separator is not found or if the escaped character is located before the > > separator, then move the separator ahead and continue searching for the > > next separator. > > > > Return the pointer to remainder string after the delimiter. If the > > separator was found, return a pointer to the character immediately after > > the delimiter (s + 1). If the separator was not found, return NULL. > > This doesn't do anything to the escape character. Presumably you want to > pass the field containing a separator down to dm_eary_create(). But you > don't want to pass the escape character itself. > > To work correctly, this code needs to remove all those escape characters > that come before separators. It probably needs to do something like: > > 1. Find a next non-escaped separator and change it to NULL, so you have > your field string. And by NULL, I mean '\0'. -Ben > > 2. Find all the escaped separators in the field string, and shift the > rest of the string over to overwrite the escape character with the rest > of the string. > > -Ben > > > > > Signed-off-by: Abhinav Jain > > --- > > drivers/md/dm-init.c | 14 ++++++++++++-- > > 1 file changed, 12 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/md/dm-init.c b/drivers/md/dm-init.c > > index 2a71bcdba92d..bef6a582a4ae 100644 > > --- a/drivers/md/dm-init.c > > +++ b/drivers/md/dm-init.c > > @@ -87,11 +87,21 @@ static void __init dm_setup_cleanup(struct list_head *devices) > > */ > > static char __init *str_field_delimit(char **str, char separator) > > { > > - char *s; > > + char *s, *escaped; > > > > - /* TODO: add support for escaped characters */ > > *str = skip_spaces(*str); > > s = strchr(*str, separator); > > + > > + /* Check for escaped character */ > > + escaped = strchr(*str, '\\'); > > + if (escaped && (s == NULL || escaped < s)) { > > + /* > > + * If escaped character comes before the separator, move > > + * the separator ahead & continue searching for next one. > > + */ > > + s = strchr(escaped + 1, separator); > > + } > > + > > /* Delimit the field and remove trailing spaces */ > > if (s) > > *s = '\0'; > > -- > > 2.34.1 > >