blob: 4d784aa8dc45fd5d392d8bd6f8dc731ce5235bf1 [file] [log] [blame]
Elliott Hughesb005d902017-02-22 14:54:15 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <errno.h>
18#include <sys/socket.h>
19#include <sys/un.h>
20
21#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
22#include <sys/_system_properties.h>
23
24#include <gtest/gtest.h>
25
26TEST(property_service, very_long_name_35166374) {
27 // Connect to the property service directly...
28 int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
29 ASSERT_NE(fd, -1);
30
31 static const char* property_service_socket = "/dev/socket/" PROP_SERVICE_NAME;
32 sockaddr_un addr = {};
33 addr.sun_family = AF_LOCAL;
34 strlcpy(addr.sun_path, property_service_socket, sizeof(addr.sun_path));
35
36 socklen_t addr_len = strlen(property_service_socket) + offsetof(sockaddr_un, sun_path) + 1;
37 ASSERT_NE(connect(fd, reinterpret_cast<sockaddr*>(&addr), addr_len), -1);
38
39 // ...so we can send it a malformed request.
40 uint32_t msg = PROP_MSG_SETPROP2;
41 uint32_t size = 0xffffffff;
42 uint32_t data = 0xdeadbeef;
43
44 ASSERT_EQ(static_cast<ssize_t>(sizeof(msg)), send(fd, &msg, sizeof(msg), 0));
45 ASSERT_EQ(static_cast<ssize_t>(sizeof(size)), send(fd, &size, sizeof(size), 0));
46 ASSERT_EQ(static_cast<ssize_t>(sizeof(data)), send(fd, &data, sizeof(data), 0));
47 ASSERT_EQ(0, close(fd));
48}