From 3da5a64a8d3f88e9f6f31bade697aa02de0e560b Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Tue, 9 Jun 2020 19:37:38 -0500 Subject: [PATCH] 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. --- builder/vmware/common/driver_parser.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/builder/vmware/common/driver_parser.go b/builder/vmware/common/driver_parser.go index d080b307a..93d4f3dcd 100644 --- a/builder/vmware/common/driver_parser.go +++ b/builder/vmware/common/driver_parser.go @@ -1996,27 +1996,31 @@ func flattenNetworkingConfig(in chan networkingCommandEntry) NetworkingConfig { // Constructor for networking file 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) tokenized := tokenizeNetworkingConfig(fromfile) 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) if err != nil { return NetworkingConfig{}, err } - // verify that it's 1.0 since that's all we support. - version := parsed_version.Number() - if version != 1.0 { + // verify that it's 1.0 since that's all we support for now. + if version := parsed_version.Number(); version != 1.0 { return NetworkingConfig{}, fmt.Errorf("Expected version %f of networking file. Received version %f.", 1.0, version) } - // convert to a configuration - result := flattenNetworkingConfig(entries) - return result, nil + // now that our version has been confirmed, we can proceed to parse the + // rest of the file and parseNetworkingConfig is free to consume rows as + // 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