diff options
Diffstat (limited to 'lib/config/config.c')
-rw-r--r-- | lib/config/config.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/config/config.c b/lib/config/config.c index 485063a3d..25a87c983 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -501,6 +501,9 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r checksum_fn_t checksum_fn, uint32_t checksum, int checksum_only, int no_dup_node_check) { + char namebuf[NAME_LEN + 1] __attribute__((aligned(8))); + int namelen = 0; + int bad_name = 0; char *fb, *fe; int r = 0; int sz, use_plain_read = 1; @@ -548,6 +551,23 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r fb = buf; + if (!(dev->flags & DEV_REGULAR)) { + memcpy(namebuf, buf, NAME_LEN); + + while (namebuf[namelen] && !isspace(namebuf[namelen]) && namebuf[namelen] != '{' && namelen < (NAME_LEN - 1)) + namelen++; + namebuf[namelen] = '\0'; + + /* + * Check that the text metadata begins with a valid name. + */ + if (!validate_name(namebuf)) { + log_warn("WARNING: Metadata location on %s at offset %llu begins with invalid name.", + dev_name(dev), (unsigned long long)offset); + bad_name = 1; + } + } + /* * The checksum passed in is the checksum from the mda_header * preceding this metadata. They should always match. @@ -557,10 +577,13 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r if (checksum_fn && checksum != (checksum_fn(checksum_fn(INITIAL_CRC, (const uint8_t *)fb, size), (const uint8_t *)(fb + size), size2))) { - log_error("%s: Checksum error at offset %" PRIu64, dev_name(dev), (uint64_t) offset); + log_warn("WARNING: Checksum error on %s at offset %llu.", dev_name(dev), (unsigned long long)offset); goto out; } + if (bad_name) + goto out; + if (!checksum_only) { fe = fb + size + size2; if (no_dup_node_check) { |