shithub: scc

Download patch

ref: 0eb2e050cb6322d122b284e2645acbf876eae176
parent: 67d90c41c1d5ef13d67cc0a3ce2bd7de1cc53037
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Dec 12 07:32:53 EST 2017

[as] Add validator of labels

Field spliting is done using file separators characters, and it means
that we can include in the label everything until the file separator,
including spaces and undesired characters.

--- a/as/expr.c
+++ b/as/expr.c
@@ -197,8 +197,20 @@
 	int c;
 	char *p;
 
-	while (isalnum(c = *endp) || c == '_' || c == '.')
-		++endp;
+	for ( ; c = *endp; ++endp) {
+		if (isalnum(c))
+			continue;
+		switch (c) {
+		case '_':
+		case '-':
+		case '.':
+		case '$':
+			continue;
+		default:
+			break;
+		}
+	}
+
 	tok2str();
 	yylval.sym = lookup(yytext, FUNDEF);
 
--- a/as/parser.c
+++ b/as/parser.c
@@ -88,6 +88,27 @@
 }
 
 static int
+validlabel(char *name)
+{
+	int c;
+
+	while ((c = *name++) != '\0') {
+		if (isalnum(c))
+			continue;
+		switch (c) {
+		case '_':
+		case '-':
+		case '.':
+		case '$':
+			continue;
+		default:
+			return 0;
+		}
+	}
+	return 1;
+}
+
+static int
 extract(char *s, struct line *lp)
 {
 	int r = 0;
@@ -97,6 +118,8 @@
 		len = strlen(lp->label);
 		if (lp->label[len-1] == ':')
 			lp->label[len-1] = '\0';
+		if (!validlabel(lp->label))
+			error("incorrect label name '%s'", lp->label);
 		r++;
 	}
 	if (lp->op = field(&s))