blob: 3a64e02723977389d4ecfe647fd3df3b45c091a1 [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
Tom Cherry81f5d3e2017-06-22 12:53:17 -070026namespace android {
27namespace init {
28
Elliott Hughesb005d902017-02-22 14:54:15 -080029TEST(property_service, very_long_name_35166374) {
30 // Connect to the property service directly...
31 int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
32 ASSERT_NE(fd, -1);
33
34 static const char* property_service_socket = "/dev/socket/" PROP_SERVICE_NAME;
35 sockaddr_un addr = {};
36 addr.sun_family = AF_LOCAL;
37 strlcpy(addr.sun_path, property_service_socket, sizeof(addr.sun_path));
38
39 socklen_t addr_len = strlen(property_service_socket) + offsetof(sockaddr_un, sun_path) + 1;
40 ASSERT_NE(connect(fd, reinterpret_cast<sockaddr*>(&addr), addr_len), -1);
41
42 // ...so we can send it a malformed request.
43 uint32_t msg = PROP_MSG_SETPROP2;
44 uint32_t size = 0xffffffff;
45 uint32_t data = 0xdeadbeef;
46
47 ASSERT_EQ(static_cast<ssize_t>(sizeof(msg)), send(fd, &msg, sizeof(msg), 0));
48 ASSERT_EQ(static_cast<ssize_t>(sizeof(size)), send(fd, &size, sizeof(size), 0));
49 ASSERT_EQ(static_cast<ssize_t>(sizeof(data)), send(fd, &data, sizeof(data), 0));
50 ASSERT_EQ(0, close(fd));
51}
Tom Cherry81f5d3e2017-06-22 12:53:17 -070052
53} // namespace init
54} // namespace android