CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
83 lines
2.9 KiB
C++
83 lines
2.9 KiB
C++
// Test that ASan detects buffer overflow on read from socket via recvfrom.
|
|
//
|
|
// RUN: %clangxx_asan %s -DRECVFROM -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RECVFROM
|
|
// RUN: %clangxx_asan %s -DSENDTO -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SENDTO
|
|
// RUN: %clangxx_asan %s -DSENDTO -o %t && %env_asan_opts=intercept_send=0 %run %t 2>&1
|
|
//
|
|
// This will try to fast unwind on Arm Thumb, where fast unwinding does not work.
|
|
// UNSUPPORTED: android, !fast-unwinder-works
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <netdb.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <pthread.h>
|
|
|
|
#define CHECK_ERROR(p, m) \
|
|
do { \
|
|
if (p) { \
|
|
fprintf(stderr, "ERROR " m "\n"); \
|
|
exit(1); \
|
|
} \
|
|
} while (0)
|
|
|
|
const int kBufSize = 10;
|
|
int sockfd;
|
|
|
|
static void *client_thread_udp(void *data) {
|
|
#ifdef SENDTO
|
|
const char buf[kBufSize / 2] = {0, };
|
|
#else
|
|
const char buf[kBufSize] = {0, };
|
|
#endif
|
|
struct sockaddr_in serveraddr;
|
|
socklen_t addrlen = sizeof(serveraddr);
|
|
|
|
int succeeded = getsockname(sockfd, (struct sockaddr *)&serveraddr, &addrlen);
|
|
CHECK_ERROR(succeeded < 0, "in getsockname");
|
|
|
|
succeeded = sendto(sockfd, buf, kBufSize, 0, (struct sockaddr *)&serveraddr,
|
|
sizeof(serveraddr));
|
|
// CHECK-SENDTO: {{READ of size 10 at 0x.* thread T1}}
|
|
// CHECK-SENDTO: {{ #1 0x.* in client_thread_udp.*recvfrom.cpp:}}[[@LINE-3]]
|
|
CHECK_ERROR(succeeded < 0, "in sending message");
|
|
return NULL;
|
|
}
|
|
|
|
int main() {
|
|
#ifdef RECVFROM
|
|
char buf[kBufSize / 2];
|
|
#else
|
|
char buf[kBufSize];
|
|
#endif
|
|
pthread_t client_thread;
|
|
struct sockaddr_in serveraddr;
|
|
|
|
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
CHECK_ERROR(sockfd < 0, "opening socket");
|
|
|
|
memset(&serveraddr, 0, sizeof(serveraddr));
|
|
serveraddr.sin_family = AF_INET;
|
|
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
serveraddr.sin_port = 0;
|
|
|
|
int bound = bind(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
|
|
CHECK_ERROR(bound < 0, "on binding");
|
|
|
|
int succeeded =
|
|
pthread_create(&client_thread, NULL, client_thread_udp, &serveraddr);
|
|
CHECK_ERROR(succeeded, "creating thread");
|
|
|
|
recvfrom(sockfd, buf, kBufSize, 0, NULL, NULL); // BOOM
|
|
// CHECK-RECVFROM: {{WRITE of size 10 at 0x.* thread T0}}
|
|
// CHECK-RECVFROM: {{ #1 0x.* in main.*recvfrom.cpp:}}[[@LINE-2]]
|
|
// CHECK-RECVFROM: {{Address 0x.* is located in stack of thread T0 at offset}}
|
|
// CHECK-RECVFROM-NEXT: in{{.*}}main{{.*}}recvfrom.cpp
|
|
succeeded = pthread_join(client_thread, NULL);
|
|
CHECK_ERROR(succeeded, "joining thread");
|
|
return 0;
|
|
}
|