Skip to contentSkip to conversation

scripts: imx: Ignore ';' and '\n' in quotes

PATCH Applied Albert Schwarzkopf 2 participants 2 messages Mar 27, 2023 – Mar 28, 2023 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: imx: Ignore ';' and '\n' in quotes

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.

---
 scripts/imx/imx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/imx/imx.c +4 -2
index 87560ad27d..fac0556308 100644
@@ -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;
 		}
Signature · 1 line
2.40.0
Applied
#1 lore raw
Quoted 10 lines · Albert Schwarzkopf

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.

---
 scripts/imx/imx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

Quoted 30 lines
scripts/imx/imx.c +4 -2
index 87560ad27d..fac0556308 100644
@@ -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;
 		}
Signature · 1 line
2.40.0
Signature · 4 lines
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 |