@@ -67,12 +67,12 @@ bool MacAddress::fromString(const char *buf) {
67
67
68
68
// Parse user entered string into MAC address
69
69
bool MacAddress::fromString6 (const char *buf) {
70
- char cs[18 ];
70
+ char cs[18 ];// 17 + 1 for null terminator
71
71
char *token;
72
72
char *next; // Unused but required
73
73
int i;
74
74
75
- strncpy (cs, buf, sizeof (cs)); // strtok modifies the buffer: copy to working buffer.
75
+ strncpy (cs, buf, sizeof (cs) - 1 ); // strtok modifies the buffer: copy to working buffer.
76
76
77
77
for (i = 0 ; i < 6 ; i++) {
78
78
token = strtok ((i == 0 ) ? cs : NULL , " :" ); // Find first or next token
@@ -86,12 +86,12 @@ bool MacAddress::fromString6(const char *buf) {
86
86
}
87
87
88
88
bool MacAddress::fromString8 (const char *buf) {
89
- char cs[24 ];
89
+ char cs[24 ];// 23 + 1 for null terminator
90
90
char *token;
91
91
char *next; // Unused but required
92
92
int i;
93
93
94
- strncpy (cs, buf, sizeof (cs)); // strtok modifies the buffer: copy to working buffer.
94
+ strncpy (cs, buf, sizeof (cs) - 1 ); // strtok modifies the buffer: copy to working buffer.
95
95
96
96
for (i = 0 ; i < 8 ; i++) {
97
97
token = strtok ((i == 0 ) ? cs : NULL , " :" ); // Find first or next token
0 commit comments