[msan] Fix dn_comp interceptor after D126851

Unpoison by strlen(dest), as dn_expand
returns the size if the compressed name (src).

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D129244
This commit is contained in:
Vitaly Buka 2022-07-06 19:03:32 -07:00
parent 41fba3c107
commit ba4435eb62
3 changed files with 81 additions and 2 deletions

View File

@ -2546,7 +2546,7 @@ INTERCEPTOR(int, DN_EXPAND_INTERCEPTOR_NAME, unsigned char const *base,
// TODO: add read check if __dn_comp intercept added
int res = REAL(DN_EXPAND_INTERCEPTOR_NAME)(base, end, src, dest, space);
if (res >= 0)
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, res + 1);
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, internal_strlen(dest) + 1);
return res;
}
# define INIT___DN_EXPAND \

View File

@ -34,12 +34,52 @@ void testWriteZeroLength() {
assert(res >= 0);
assert(strlen(output) == 0);
__msan_check_mem_is_initialized(output, strlen(output) + 1);
__msan_check_mem_is_initialized(output, res);
}
void testComp() {
char unsigned msg[1024];
char unsigned *mb = msg;
char unsigned *me = msg + sizeof(msg);
char unsigned **pb = (char unsigned **)mb;
pb[0] = msg;
pb[1] = nullptr;
mb += 64;
char unsigned **pe = (char unsigned **)mb;
char unsigned *n1 = mb;
int res = dn_comp("llvm.org", mb, me - mb, pb, pe);
assert(res == 10);
mb += res;
char unsigned *n2 = mb;
res = dn_comp("lab.llvm.org", mb, me - mb, pb, pe);
assert(res == 6);
mb += res;
{
char output[1024];
res = dn_expand(msg, msg + sizeof(msg), n1, output, sizeof(output));
fprintf(stderr, "%d\n", res);
assert(res == 10);
assert(strlen(output) == 8);
__msan_check_mem_is_initialized(output, strlen(output) + 1);
}
{
char output[1024];
res = dn_expand(msg, msg + sizeof(msg), n2, output, sizeof(output));
assert(res == 6);
assert(strlen(output) == 12);
__msan_check_mem_is_initialized(output, strlen(output) + 1);
}
}
int main(int iArgc, const char *szArgv[]) {
testWrite();
testWriteZeroLength();
testComp();
return 0;
}

View File

@ -34,9 +34,48 @@ void testWriteZeroLength() {
assert(strcmp(output, "") == 0);
}
void testComp() {
char unsigned msg[1024];
char unsigned *mb = msg;
char unsigned *me = msg + sizeof(msg);
char unsigned **pb = (char unsigned **)mb;
pb[0] = msg;
pb[1] = nullptr;
mb += 64;
char unsigned **pe = (char unsigned **)mb;
char unsigned *n1 = mb;
int res = dn_comp("llvm.org", mb, me - mb, pb, pe);
assert(res == 10);
mb += res;
char unsigned *n2 = mb;
res = dn_comp("lab.llvm.org", mb, me - mb, pb, pe);
assert(res == 6);
mb += res;
{
char output[1024];
res = dn_expand(msg, msg + sizeof(msg), n1, output, sizeof(output));
fprintf(stderr, "%d\n", res);
assert(res == 10);
assert(strcmp(output, "llvm.org") == 0);
}
{
char output[1024];
res = dn_expand(msg, msg + sizeof(msg), n2, output, sizeof(output));
assert(res == 6);
assert(strcmp(output, "lab.llvm.org") == 0);
}
}
int main(int iArgc, const char *szArgv[]) {
testWrite();
testWriteZeroLength();
testComp();
return 0;
}