From 8f48e7b1e991375f6b03fac09a4f4416eb2f1afc Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Mon, 16 Mar 2020 10:49:45 +0100 Subject: [PATCH] util/xmlconfig: add new sha1 application attribute MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is useful to enable workarounds for applications with a generic name. For instance all games made with the YoYo game engine have the same executable name "runner". Reviewed-by: Marek Olšák Part-of: --- src/util/00-mesa-defaults.conf | 3 ++- src/util/xmlconfig.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf index 72c415abef8..d078b938021 100644 --- a/src/util/00-mesa-defaults.conf +++ b/src/util/00-mesa-defaults.conf @@ -34,7 +34,8 @@ TODO: document the other workarounds. + executable CDATA #REQUIRED + sha1 CDATA #IMPLIED> diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c index b036145269e..0ef67ab7b76 100644 --- a/src/util/xmlconfig.c +++ b/src/util/xmlconfig.c @@ -46,6 +46,7 @@ #include "strndup.h" #include "xmlconfig.h" #include "u_process.h" +#include "os_file.h" /* For systems like Hurd */ #ifndef PATH_MAX @@ -780,13 +781,39 @@ parseAppAttr(struct OptConfData *data, const XML_Char **attr) { uint32_t i; const XML_Char *exec = NULL; + const XML_Char *sha1 = NULL; for (i = 0; attr[i]; i += 2) { if (!strcmp (attr[i], "name")) /* not needed here */; else if (!strcmp (attr[i], "executable")) exec = attr[i+1]; + else if (!strcmp (attr[i], "sha1")) sha1 = attr[i+1]; else XML_WARNING("unknown application attribute: %s.", attr[i]); } - if (exec && strcmp (exec, data->execName)) + if (exec && strcmp (exec, data->execName)) { data->ignoringApp = data->inApp; + } else if (sha1) { + if (strlen(sha1) != 40) { + XML_WARNING("Incorrect sha1 application attribute"); + data->ignoringApp = data->inApp; + } else { + size_t len; + char* content; + char path[PATH_MAX]; + if (util_get_process_exec_path(path, ARRAY_SIZE(path)) > 0 && + (content = os_read_file(path, &len))) { + uint8_t sha1x[20]; + char sha1s[40]; + _mesa_sha1_compute(content, len, sha1x); + _mesa_sha1_format((char*) sha1s, sha1x); + free(content); + + if (memcmp(sha1, sha1s, SHA1_DIGEST_LENGTH)) { + data->ignoringApp = data->inApp; + } + } else { + data->ignoringApp = data->inApp; + } + } + } } /** \brief Parse attributes of an application element. */ -- 2.30.2