util/xmlconfig: fix sha1 comparison code
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Fri, 3 Apr 2020 07:25:05 +0000 (09:25 +0200)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Fri, 3 Apr 2020 09:44:00 +0000 (11:44 +0200)
Fixes: 8f48e7b1e99 ("util/xmlconfig: add new sha1 application attribute")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2730
Reviewed-by: Dave Airlie <airlied@redhat.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4426>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4426>

src/util/xmlconfig.c

index 0ef67ab7b76a12425b6b1549fbff8560c0edcc6f..4ddad79e8bdebf983d175f1056c028191ee02777 100644 (file)
@@ -791,7 +791,8 @@ parseAppAttr(struct OptConfData *data, const XML_Char **attr)
     if (exec && strcmp (exec, data->execName)) {
         data->ignoringApp = data->inApp;
     } else if (sha1) {
-        if (strlen(sha1) != 40) {
+        /* SHA1_DIGEST_STRING_LENGTH includes terminating null byte */
+        if (strlen(sha1) != (SHA1_DIGEST_STRING_LENGTH - 1)) {
             XML_WARNING("Incorrect sha1 application attribute");
             data->ignoringApp = data->inApp;
         } else {
@@ -800,13 +801,13 @@ parseAppAttr(struct OptConfData *data, const XML_Char **attr)
             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];
+                uint8_t sha1x[SHA1_DIGEST_LENGTH];
+                char sha1s[SHA1_DIGEST_STRING_LENGTH];
                 _mesa_sha1_compute(content, len, sha1x);
                 _mesa_sha1_format((char*) sha1s, sha1x);
                 free(content);
 
-                if (memcmp(sha1, sha1s, SHA1_DIGEST_LENGTH)) {
+                if (strcmp(sha1, sha1s)) {
                     data->ignoringApp = data->inApp;
                 }
             } else {