Fixed a race in the ReadNetworkingConfig implementation from the parsers belonging to the vmware builders that existed between reading the version and consuming tokens from the rest of the file.
This commit is contained in:
parent
46aea0f14b
commit
3da5a64a8d
|
@ -1996,27 +1996,31 @@ func flattenNetworkingConfig(in chan networkingCommandEntry) NetworkingConfig {
|
||||||
// Constructor for networking file
|
// Constructor for networking file
|
||||||
func ReadNetworkingConfig(fd *os.File) (NetworkingConfig, error) {
|
func ReadNetworkingConfig(fd *os.File) (NetworkingConfig, error) {
|
||||||
|
|
||||||
// start piecing together different parts of the file
|
// start piecing together all of the differents parts of the file and split
|
||||||
|
// it into its individual rows.
|
||||||
fromfile := consumeFile(fd)
|
fromfile := consumeFile(fd)
|
||||||
tokenized := tokenizeNetworkingConfig(fromfile)
|
tokenized := tokenizeNetworkingConfig(fromfile)
|
||||||
rows := splitNetworkingConfig(tokenized)
|
rows := splitNetworkingConfig(tokenized)
|
||||||
entries := parseNetworkingConfig(rows)
|
|
||||||
|
|
||||||
// parse the version
|
// consume the version _first_. this is important because if the version is
|
||||||
|
// wrong, then there's likely tokens that we won't know how to interpret.
|
||||||
parsed_version, err := networkingReadVersion(<-rows)
|
parsed_version, err := networkingReadVersion(<-rows)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NetworkingConfig{}, err
|
return NetworkingConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify that it's 1.0 since that's all we support.
|
// verify that it's 1.0 since that's all we support for now.
|
||||||
version := parsed_version.Number()
|
if version := parsed_version.Number(); version != 1.0 {
|
||||||
if version != 1.0 {
|
|
||||||
return NetworkingConfig{}, fmt.Errorf("Expected version %f of networking file. Received version %f.", 1.0, version)
|
return NetworkingConfig{}, fmt.Errorf("Expected version %f of networking file. Received version %f.", 1.0, version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert to a configuration
|
// now that our version has been confirmed, we can proceed to parse the
|
||||||
result := flattenNetworkingConfig(entries)
|
// rest of the file and parseNetworkingConfig is free to consume rows as
|
||||||
return result, nil
|
// much as it wants to.
|
||||||
|
entries := parseNetworkingConfig(rows)
|
||||||
|
|
||||||
|
// convert what we've parsed into a configuration that's easy to interpret
|
||||||
|
return flattenNetworkingConfig(entries), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// netmapper interface
|
// netmapper interface
|
||||||
|
|
Loading…
Reference in New Issue