commit 706b901d7969c3000fac48659de8bb99ff117d62
parent fc1f6bcd51702c51fde660bb20de3666f19792a8
Author: nibo <nibo@relim.de>
Date: Sun, 13 Oct 2024 17:57:15 +0200
Improve parser error catching
Diffstat:
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/chordpro.c b/chordpro.c
@@ -2668,7 +2668,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config)
if (buf == '\n') {
g_line_number++;
}
- // printf("state: %s, prev_state: %s, prev_buf: %c, buf: %c\n", cho_state_to_string(state), cho_state_to_string(prev_state), prev_buf, buf);
+ // printf("state: %s, prev_state: %s, prev_buf: %c, buf: %c\n", state_enums[state], state_enums[prev_state], prev_buf, buf);
if (buf == '\r') {
continue;
}
@@ -2965,6 +2965,14 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config)
state = STATE_LYRICS;
break;
}
+ if (buf == '{') {
+ cho_log(LOG_ERR, "Can't start a new directive if the previous one is not closed yet.");
+ return NULL;
+ }
+ if (buf == '\n') {
+ cho_log(LOG_ERR, "Can't have a newline in a directive name.");
+ return NULL;
+ }
if (buf == ':' || buf == ' ') {
directive_name[dn] = 0;
dn = 0;
@@ -3231,6 +3239,14 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config)
state = STATE_LYRICS;
break;
}
+ if (buf == '{') {
+ cho_log(LOG_ERR, "Can't start a new directive if the previous one is not closed yet.");
+ return NULL;
+ }
+ if (buf == '\n') {
+ cho_log(LOG_ERR, "Can't have a newline in a directive value.");
+ return NULL;
+ }
directive_value[dv] = buf;
dv++;
break;
@@ -3368,6 +3384,10 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config)
state = STATE_MARKUP_ATTR_NAME;
break;
}
+ if (buf == '\n') {
+ cho_log(LOG_ERR, "Newline character inside a tag name is invalid.");
+ return NULL;
+ }
if (t == 5) {
cho_log(LOG_ERR, "Begin tag name is too long.");
return NULL;