threads / discuss / 2074

Improve config file escape sanity checking

Subject: Improve config file escape sanity checking

## tl;dr

One message between Oct 11, 2005 and Oct 11, 2005.

replies: 0people: 1as markdown or json

Linus Torvalds· Oct 11, 2005, 19:13 UTC · lore

I had meant to disallow unknown escape characters in the config file parser, but instead an unknown escaped character would silently pass through as itself. That's correct for some cases (notably '\' itself), but wasn't correct in general.

This fixes it, and makes the parser write a nice error message if the config file contains bogus escaped characters.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/config.c b/config.c
index f3c4fa4..510456c 100644
--- a/config.c
+++ b/config.c
@@ -64,7 +64,12 @@ static char *parse_value(void)
 			case 'n':
 				c = '\n';
 				break;
-			return NULL;
+			/* Some characters escape as themselves */
+			case '\\': case '"':
+				break;
+			/* Reject unknown escape sequences */
+			default:
+				return NULL;
 			}
 			value[len++] = c;
 			continue;

← back to recent threads