mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] scripts: imx: Ignore ';' and '\n' in quotes
@ 2023-03-27  8:48 Albert Schwarzkopf
  2023-03-28  8:22 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Albert Schwarzkopf @ 2023-03-27  8:48 UTC (permalink / raw)
  To: barebox

The current behaviour treats semicolons the same as end of line.
This breaks when they are found inside quoted strings, as is the
case for PKCS#11 URIs for example.

Ignore newlines and semicolons in quotes when parsing commands.

Signed-off-by: Albert Schwarzkopf <a.schwarzkopf@phytec.de>
---
 scripts/imx/imx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/imx/imx.c b/scripts/imx/imx.c
index 87560ad27d..fac0556308 100644
--- a/scripts/imx/imx.c
+++ b/scripts/imx/imx.c
@@ -675,6 +675,7 @@ static char *readcmd(struct config_data *data, FILE *f)
 	static char *buf;
 	char *str;
 	ssize_t ret;
+	int inquotes = 0;
 
 	if (!buf) {
 		buf = malloc(4096);
@@ -689,8 +690,9 @@ static char *readcmd(struct config_data *data, FILE *f)
 		ret = fread(str, 1, 1, f);
 		if (!ret)
 			return strlen(buf) ? buf : NULL;
-
-		if (*str == '\n' || *str == ';') {
+		if (*str == '"') {
+			inquotes = !inquotes;
+		} else if ((*str == '\n' || *str == ';') && !inquotes) {
 			*str = 0;
 			return buf;
 		}
-- 
2.40.0




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] scripts: imx: Ignore ';' and '\n' in quotes
  2023-03-27  8:48 [PATCH] scripts: imx: Ignore ';' and '\n' in quotes Albert Schwarzkopf
@ 2023-03-28  8:22 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-03-28  8:22 UTC (permalink / raw)
  To: Albert Schwarzkopf; +Cc: barebox

On Mon, Mar 27, 2023 at 10:48:27AM +0200, Albert Schwarzkopf wrote:
> The current behaviour treats semicolons the same as end of line.
> This breaks when they are found inside quoted strings, as is the
> case for PKCS#11 URIs for example.
> 
> Ignore newlines and semicolons in quotes when parsing commands.
> 
> Signed-off-by: Albert Schwarzkopf <a.schwarzkopf@phytec.de>
> ---
>  scripts/imx/imx.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/scripts/imx/imx.c b/scripts/imx/imx.c
> index 87560ad27d..fac0556308 100644
> --- a/scripts/imx/imx.c
> +++ b/scripts/imx/imx.c
> @@ -675,6 +675,7 @@ static char *readcmd(struct config_data *data, FILE *f)
>  	static char *buf;
>  	char *str;
>  	ssize_t ret;
> +	int inquotes = 0;
>  
>  	if (!buf) {
>  		buf = malloc(4096);
> @@ -689,8 +690,9 @@ static char *readcmd(struct config_data *data, FILE *f)
>  		ret = fread(str, 1, 1, f);
>  		if (!ret)
>  			return strlen(buf) ? buf : NULL;
> -
> -		if (*str == '\n' || *str == ';') {
> +		if (*str == '"') {
> +			inquotes = !inquotes;
> +		} else if ((*str == '\n' || *str == ';') && !inquotes) {
>  			*str = 0;
>  			return buf;
>  		}
> -- 
> 2.40.0
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-28  8:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-27  8:48 [PATCH] scripts: imx: Ignore ';' and '\n' in quotes Albert Schwarzkopf
2023-03-28  8:22 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox