In both clang-10 and clang-12, a WITH_MSAN build of the server would crash with SIGSEGV if the ENCRYPT() function is evaluated. The problem seems to be related to the MSAN interceptor of the crypt() function. I was unable to reproduce this with a simple test program:
#include <crypt.h>
|
#include <stdio.h>
|
|
int main(int argc, char **argv)
|
{
|
printf("crypt: %s\n", crypt(argv[1], "123"));
|
return 0;
|
}
|
clang-10 -fsanitize=undefined crypt.c -lcrypt
|
./a.out foo
|
I see that re-entrant versions of the C function crypt() exist, but we are using the original version with LOCK_crypt around it. Perhaps one of the other variants of the function would be intercepted better?
Note: No memory appears to be uninitialized. The following patch did not trigger anything; the very first sign of trouble was the SIGSEGV.
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
|
index 0635556be40..3f9e023c793 100644
|
--- a/sql/item_strfunc.cc
|
+++ b/sql/item_strfunc.cc
|
@@ -2280,6 +2280,8 @@ String *Item_func_encrypt::val_str(String *str)
|
salt_ptr= salt_str->c_ptr_safe();
|
}
|
mysql_mutex_lock(&LOCK_crypt);
|
+ MEM_CHECK_DEFINED(res->c_ptr_safe(), res->length);
|
+ MEM_CHECK_DEFINED(salt_ptr, 2);
|
char *tmp= crypt(res->c_ptr_safe(),salt_ptr);
|
if (!tmp)
|
{
|
To work around this problem, I will move some encrypt() test cases from the files main.view and main.func_encrypt to the test main.func_crypt, which will be disabled in cmake -DWITH_MSAN=ON builds for now.
{"report":{"fcp":1850.6999998092651,"ttfb":610.7999997138977,"pageVisibility":"visible","entityId":108433,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"9b8b90e7-b686-4d99-831e-2de7a7e7da6d","navigationType":0,"readyForUser":1934.5999999046326,"redirectCount":0,"resourceLoadedEnd":2570.0999999046326,"resourceLoadedStart":619.8999996185303,"resourceTiming":[{"duration":741,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":619.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":619.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1360.8999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":741,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":620.1999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":620.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1361.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":749.8999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":620.5,"connectEnd":620.5,"connectStart":620.5,"domainLookupEnd":620.5,"domainLookupStart":620.5,"fetchStart":620.5,"redirectEnd":0,"redirectStart":0,"requestStart":620.5,"responseEnd":1370.3999996185303,"responseStart":1370.2999997138977,"secureConnectionStart":620.5},{"duration":806.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":621.0999999046326,"connectEnd":621.0999999046326,"connectStart":621.0999999046326,"domainLookupEnd":621.0999999046326,"domainLookupStart":621.0999999046326,"fetchStart":621.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":621.0999999046326,"responseEnd":1427.1999998092651,"responseStart":1427.1999998092651,"secureConnectionStart":621.0999999046326},{"duration":810.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":621.2999997138977,"connectEnd":621.2999997138977,"connectStart":621.2999997138977,"domainLookupEnd":621.2999997138977,"domainLookupStart":621.2999997138977,"fetchStart":621.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":621.2999997138977,"responseEnd":1431.5,"responseStart":1431.5,"secureConnectionStart":621.2999997138977},{"duration":810.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":621.3999996185303,"connectEnd":621.3999996185303,"connectStart":621.3999996185303,"domainLookupEnd":621.3999996185303,"domainLookupStart":621.3999996185303,"fetchStart":621.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":621.3999996185303,"responseEnd":1432.0999999046326,"responseStart":1432.0999999046326,"secureConnectionStart":621.3999996185303},{"duration":810.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":621.5999999046326,"connectEnd":621.5999999046326,"connectStart":621.5999999046326,"domainLookupEnd":621.5999999046326,"domainLookupStart":621.5999999046326,"fetchStart":621.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":621.5999999046326,"responseEnd":1432.5,"responseStart":1432.5,"secureConnectionStart":621.5999999046326},{"duration":904.3000001907349,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":621.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":621.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1526.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":811.1999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":622,"connectEnd":622,"connectStart":622,"domainLookupEnd":622,"domainLookupStart":622,"fetchStart":622,"redirectEnd":0,"redirectStart":0,"requestStart":622,"responseEnd":1433.1999998092651,"responseStart":1433.1999998092651,"secureConnectionStart":622},{"duration":904.0999999046326,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":622.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":622.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1526.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":811.5999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":622.1999998092651,"connectEnd":622.1999998092651,"connectStart":622.1999998092651,"domainLookupEnd":622.1999998092651,"domainLookupStart":622.1999998092651,"fetchStart":622.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":622.1999998092651,"responseEnd":1433.7999997138977,"responseStart":1433.7999997138977,"secureConnectionStart":622.1999998092651},{"duration":1939.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":629.6999998092651,"connectEnd":629.6999998092651,"connectStart":629.6999998092651,"domainLookupEnd":629.6999998092651,"domainLookupStart":629.6999998092651,"fetchStart":629.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":629.6999998092651,"responseEnd":2569.0999999046326,"responseStart":2569.0999999046326,"secureConnectionStart":629.6999998092651},{"duration":1939.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":630.3999996185303,"connectEnd":630.3999996185303,"connectStart":630.3999996185303,"domainLookupEnd":630.3999996185303,"domainLookupStart":630.3999996185303,"fetchStart":630.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":630.3999996185303,"responseEnd":2570.0999999046326,"responseStart":2570.0999999046326,"secureConnectionStart":630.3999996185303},{"duration":294.09999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1538.5,"connectEnd":1538.5,"connectStart":1538.5,"domainLookupEnd":1538.5,"domainLookupStart":1538.5,"fetchStart":1538.5,"redirectEnd":0,"redirectStart":0,"requestStart":1538.5,"responseEnd":1832.5999999046326,"responseStart":1832.5999999046326,"secureConnectionStart":1538.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":441,"responseStart":611,"responseEnd":630,"domLoading":615,"domInteractive":2606,"domContentLoadedEventStart":2606,"domContentLoadedEventEnd":2649,"domComplete":3210,"loadEventStart":3210,"loadEventEnd":3211,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2587.0999999046326},{"name":"bigPipe.sidebar-id.end","time":2588.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":2588.199999809265},{"name":"bigPipe.activity-panel-pipe-id.end","time":2589.5},{"name":"activityTabFullyLoaded","time":2661.5999999046326}],"measures":[],"correlationId":"5b550feb5e6df5","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":104,"dbReadsTimeInMs":14,"dbConnsTimeInMs":24,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Test program not crashing on debian12/clang-19
buildbot@d701c4dff4b2:/build$ clang -fsanitize=undefined test.c -lcrypt
buildbot@d701c4dff4b2:/build$ ./a.out foo
crypt: 12o7559gAGYWY
buildbot@d701c4dff4b2:/build$ rm a.out
buildbot@d701c4dff4b2:/build$ clang -fsanitize=memory test.c -lcrypt
buildbot@d701c4dff4b2:/build$ ./a.out food
crypt: 12jorgcEoPNfk
buildbot@d701c4dff4b2:/build$ clang --version
Debian clang version 19.1.2 (++20241001023520+d5498c39fe6a-1~exp1~20241001143639.51)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
buildbot@d701c4dff4b2:/build$ ls /msan-libs/
bin libc++abi.so.1.0 libfmt.so.9 libgnutls.so.30.34.3 libnettle.so.8 libpcre2-posix.so libunwind.so.1.0
include libcrack.so libfmt.so.9.1.0 libhogweed.so libodbc.so libpcre2-posix.so.3 libxml2.so
libc++.so libcrack.so.2 libgmp.so libhogweed.so.6 libodbc.so.2 libpcre2-posix.so.3.0.4 libxml2.so.2
libc++.so.1 libcrack.so.2.9.0 libgmp.so.10 libidn2.so libodbc.so.2.0.0 libssl.so libxml2.so.2.9.14
libc++.so.1.0 libcrypto.so libgmp.so.10.4.1 libidn2.so.0 libpcre2-8.so libssl.so.3
libc++abi.so libcrypto.so.3 libgnutls.so libidn2.so.0.3.8 libpcre2-8.so.0 libunwind.so
libc++abi.so.1 libfmt.so libgnutls.so.30 libnettle.so libpcre2-8.so.0.11.2 libunwind.so.1