summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHung-Te Lin <hungte@chromium.org>2018-11-05 10:15:41 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-11-07 06:35:06 -0800
commit4c56ba267ecc722d929e7720789ea6183c54bd2a (patch)
tree8a4fdbcf8233dcd64c250856d35939d7f7199aba
parentf067d5a14dde459432940a1e519eacdb75282281 (diff)
downloadvboot-4c56ba267ecc722d929e7720789ea6183c54bd2a.tar.gz
futility: update: Strip \xFF from version string
If some system that firmware RW sections were damaged, the firmware string may become '\xFF' (flash erased content). We do not want to see that as version string, and this will help FAFT testing. BUG=chromium:899901 TEST=TEST=make futil; tests/futility/run_test_scripts.sh $(pwd)/build/futility BRANCH=None Change-Id: I947ec3c8286a022163abf01ae1d8ab5747aacf08 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1317050 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--futility/updater.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/futility/updater.c b/futility/updater.c
index d63549a4..f5c75e45 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -116,17 +116,23 @@ static void updater_remove_all_temp_files(struct updater_config *cfg)
/*
* Strip a string (usually from shell execution output) by removing all the
- * trailing space characters (space, new line, tab, ... etc).
+ * trailing characters in pattern. If pattern is NULL, match by space type
+ * characters (space, new line, tab, ... etc).
*/
-static void strip(char *s)
+static void strip(char *s, const char *pattern)
{
int len;
assert(s);
len = strlen(s);
while (len-- > 0) {
- if (!isascii(s[len]) || !isspace(s[len]))
- break;
+ if (pattern) {
+ if (!strchr(pattern, s[len]))
+ break;
+ } else {
+ if (!isascii(s[len]) || !isspace(s[len]))
+ break;
+ }
s[len] = '\0';
}
}
@@ -152,7 +158,7 @@ char *host_shell(const char *command)
}
if (fgets(buf, sizeof(buf), fp))
- strip(buf);
+ strip(buf, NULL);
result = pclose(fp);
if (!WIFEXITED(result) || WEXITSTATUS(result) != 0) {
DEBUG("Execution failure with exit code %d: %s",
@@ -297,7 +303,7 @@ static int host_flashrom(enum flashrom_ops op, const char *image_path,
}
result = host_shell(command);
- strip(result);
+ strip(result, NULL);
free(command);
DEBUG("wp-status: %s", result);
@@ -569,6 +575,11 @@ static int load_firmware_version(struct firmware_image *image,
find_firmware_section(&fwid, image, section_name);
if (fwid.size) {
*version = strndup((const char*)fwid.data, fwid.size);
+ /*
+ * For 'system current' images, the version string may contain
+ * invalid characters that we do want to strip.
+ */
+ strip(*version, "\xff");
return 0;
}
*version = strdup("");