Skip to content

Commit 94077a3

Browse files
Enforce fqbn characters validation
1 parent b153250 commit 94077a3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: internal/arduino/cores/fqbn.go

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package cores
1717

1818
import (
1919
"fmt"
20+
"regexp"
2021
"strings"
2122

2223
properties "github.com/arduino/go-properties-orderedmap"
@@ -57,6 +58,13 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
5758
if fqbn.BoardID == "" {
5859
return nil, fmt.Errorf(tr("empty board identifier"))
5960
}
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+
}
6068
if len(fqbnParts) > 3 {
6169
for _, pair := range strings.Split(fqbnParts[3], ",") {
6270
parts := strings.SplitN(pair, "=", 2)
@@ -68,6 +76,14 @@ func ParseFQBN(fqbnIn string) (*FQBN, error) {
6876
if k == "" {
6977
return nil, fmt.Errorf(tr("invalid config option: %s"), pair)
7078
}
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+
}
7187
fqbn.Configs.Set(k, v)
7288
}
7389
}

0 commit comments

Comments
 (0)