@@ -17,6 +17,7 @@ package cores
17
17
18
18
import (
19
19
"fmt"
20
+ "regexp"
20
21
"strings"
21
22
22
23
properties "github.com/arduino/go-properties-orderedmap"
@@ -57,6 +58,13 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
57
58
if fqbn .BoardID == "" {
58
59
return nil , fmt .Errorf (tr ("empty board identifier" ))
59
60
}
61
+ // Check if the fqbn contains invalid characters
62
+ fqbnValidationRegex := regexp .MustCompile (`^[a-zA-Z0-9_.-]*$` )
63
+ for i := 0 ; i < 3 ; i ++ {
64
+ if ! fqbnValidationRegex .MatchString (fqbnParts [i ]) {
65
+ return nil , fmt .Errorf (tr ("fqbn's field %s contains an invalid character" ), fqbnParts [i ])
66
+ }
67
+ }
60
68
if len (fqbnParts ) > 3 {
61
69
for _ , pair := range strings .Split (fqbnParts [3 ], "," ) {
62
70
parts := strings .SplitN (pair , "=" , 2 )
@@ -68,6 +76,14 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
68
76
if k == "" {
69
77
return nil , fmt .Errorf (tr ("invalid config option: %s" ), pair )
70
78
}
79
+ if ! fqbnValidationRegex .MatchString (k ) {
80
+ return nil , fmt .Errorf (tr ("config key %s contains an invalid character" ), k )
81
+ }
82
+ // The config value can also contain the = symbol
83
+ valueValidationRegex := regexp .MustCompile (`^[a-zA-Z0-9=_.-]*$` )
84
+ if ! valueValidationRegex .MatchString (v ) {
85
+ return nil , fmt .Errorf (tr ("config value %s contains an invalid character" ), v )
86
+ }
71
87
fqbn .Configs .Set (k , v )
72
88
}
73
89
}
0 commit comments