This is an archive of the discontinued LLVM Phabricator instance.

[Sanitizer] Fix the implementation of internal_fstat on LoongArch
ClosedPublic

Authored by tangyouling on Nov 21 2022, 3:49 AM.

Details

Summary

If pathname is an empty string and the AT_EMPTY_PATH flag is specified in flags,
statx pathname argument is of type const char *restrict, so it should be ""
instead of 0.

Diff Detail

Event Timeline

tangyouling created this revision.Nov 21 2022, 3:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 21 2022, 3:49 AM
tangyouling requested review of this revision.Nov 21 2022, 3:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 21 2022, 3:49 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
tangyouling added a reviewer: Restricted Project.Nov 21 2022, 3:50 AM
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/stat.h>
#include <linux/stat.h>
#include <linux/fcntl.h>

int main(int argc, char **argv)
{
        int fd, ret;
        struct statx bufx;

        fd = open(*argv, O_RDONLY);
        if (fd < 0)
                printf("open %s failed\n", *argv);

        ret = syscall(__NR_statx ,fd, 0, AT_EMPTY_PATH, STATX_BASIC_STATS, (void *)&bufx);
        if (ret < 0)
                printf("statx(%s) failed, ret %d\n", *argv, ret);

        printf("statx(%s) successed, ret %d\n", *argv, ret);

        close(fd);

        return 0;
}

$ gcc test-statx.c
$ ./a.out a.out 
statx(./a.out) fail, ret -1
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/stat.h>
#include <linux/stat.h>
#include <linux/fcntl.h>

int main(int argc, char **argv)
{
        int fd, ret;
        struct statx bufx;

        fd = open(*argv, O_RDONLY);
        if (fd < 0)
                printf("open %s failed\n", *argv);

        ret = syscall(__NR_statx ,fd, "", AT_EMPTY_PATH, STATX_BASIC_STATS, (void *)&bufx);
        if (ret < 0)
                printf("statx(%s) failed, ret %d\n", *argv, ret);

        printf("statx(%s) successed, ret %d\n", *argv, ret);

        close(fd);

        return 0;
}

$ gcc test-statx.c
$ ./a.out 
statx(./a.out) successed, ret 0
xry111 accepted this revision.Nov 21 2022, 3:55 AM

LGTM, thanks for fixing my stupid error!

Not sure how I wrote "0" here in the first place :(.

This revision is now accepted and ready to land.Nov 21 2022, 3:55 AM
xen0n accepted this revision.Nov 21 2022, 3:57 AM

we all gotta read manpages real hard

SixWeining accepted this revision.Nov 21 2022, 4:01 AM
lixing-star accepted this revision.Nov 21 2022, 4:33 AM