* [PATCH] dm: Add support for escaped characters in str_field_delimit()
@ 2024-06-09 14:17 Abhinav Jain
2024-06-10 17:11 ` Benjamin Marzinski
0 siblings, 1 reply; 4+ messages in thread
From: Abhinav Jain @ 2024-06-09 14:17 UTC (permalink / raw)
To: agk, snitzer, mpatocka, dm-devel, linux-kernel
Cc: skhan, javier.carrasco.cruz, jain.abhinav177
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.
Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] dm: Add support for escaped characters in str_field_delimit()
2024-06-09 14:17 [PATCH] dm: Add support for escaped characters in str_field_delimit() Abhinav Jain
@ 2024-06-10 17:11 ` Benjamin Marzinski
2024-06-10 17:28 ` Benjamin Marzinski
0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Marzinski @ 2024-06-10 17:11 UTC (permalink / raw)
To: Abhinav Jain
Cc: agk, snitzer, mpatocka, dm-devel, linux-kernel, skhan,
javier.carrasco.cruz
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.
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 <jain.abhinav177@gmail.com>
> ---
> 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
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] dm: Add support for escaped characters in str_field_delimit()
2024-06-10 17:11 ` Benjamin Marzinski
@ 2024-06-10 17:28 ` Benjamin Marzinski
2024-06-13 16:30 ` Abhinav Jain
0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Marzinski @ 2024-06-10 17:28 UTC (permalink / raw)
To: Abhinav Jain
Cc: agk, snitzer, mpatocka, dm-devel, linux-kernel, skhan,
javier.carrasco.cruz
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 <jain.abhinav177@gmail.com>
> > ---
> > 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
> >
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] dm: Add support for escaped characters in str_field_delimit()
2024-06-10 17:28 ` Benjamin Marzinski
@ 2024-06-13 16:30 ` Abhinav Jain
0 siblings, 0 replies; 4+ messages in thread
From: Abhinav Jain @ 2024-06-13 16:30 UTC (permalink / raw)
To: bmarzins
Cc: agk, dm-devel, jain.abhinav177, javier.carrasco.cruz,
linux-kernel, mpatocka, skhan, snitzer
On Mon, Jun 10, 2024 at 01:11:40PM -0400, Benjamin Marzinski wrote:
> 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.
>
> 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
Hi Ben,
I realised I should have done better testing after processing your feedback.
I have accordingly modified the code and shared a v2:
https://lore.kernel.org/all/20240613162632.38065-1-jain.abhinav177@gmail.com/
Please help review and provide feedback again. Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-13 16:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-09 14:17 [PATCH] dm: Add support for escaped characters in str_field_delimit() Abhinav Jain
2024-06-10 17:11 ` Benjamin Marzinski
2024-06-10 17:28 ` Benjamin Marzinski
2024-06-13 16:30 ` Abhinav Jain
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox