diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-09-28 10:04:56 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-09-28 12:21:40 +0200 |
| commit | eea5f51ff6a3382debe76e65a7eb194baf2930bd (patch) | |
| tree | 3ad58e410e1c0a8e4bf228aebe6bf5f7fb23b0ca | |
| parent | 38c78d5c07a1296817ae0ac9b895ee62cf691ce2 (diff) | |
executor: check for \n in fail/exitf messages
| -rw-r--r-- | executor/common_bsd.h | 4 | ||||
| -rw-r--r-- | executor/common_linux.h | 14 | ||||
| -rw-r--r-- | executor/executor.cc | 2 | ||||
| -rw-r--r-- | executor/style_test.go | 7 | ||||
| -rw-r--r-- | pkg/csource/generated.go | 18 |
5 files changed, 26 insertions, 19 deletions
diff --git a/executor/common_bsd.h b/executor/common_bsd.h index 01eaa522c..a98d3e4cb 100644 --- a/executor/common_bsd.h +++ b/executor/common_bsd.h @@ -192,7 +192,7 @@ static void initialize_tun(int tun_id) #endif // SYZ_EXECUTOR if (tun_id < 0 || tun_id >= MAX_TUN) { - fail("tun_id out of range %d\n", tun_id); + fail("tun_id out of range %d", tun_id); } char tun_device[sizeof(TUN_DEVICE)]; @@ -219,7 +219,7 @@ static void initialize_tun(int tun_id) #endif if (tunfd == -1) { #if SYZ_EXECUTOR - fail("tun: can't open %s\n", tun_device); + fail("tun: can't open %s", tun_device); #else printf("tun: can't open %s: errno=%d\n", tun_device, errno); return; diff --git a/executor/common_linux.h b/executor/common_linux.h index 63b769f4c..ab371d7e4 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -626,7 +626,7 @@ static void netlink_devlink_netns_move(const char* bus_name, const char* dev_nam sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) - fail("socket(AF_NETLINK) failed\n"); + fail("socket(AF_NETLINK) failed"); id = netlink_query_family_id(&nlmsg, sock, DEVLINK_FAMILY_NAME); if (id == -1) @@ -659,7 +659,7 @@ static void initialize_devlink_ports(const char* bus_name, const char* dev_name, int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) - fail("socket(AF_NETLINK) failed\n"); + fail("socket(AF_NETLINK) failed"); int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (rtsock == -1) @@ -978,7 +978,7 @@ static void initialize_wifi_devices(void) mac_addr[5] = device_id; int ret = hwsim80211_create_device(&nlmsg, sock, hwsim_family_id, mac_addr); if (ret < 0) - fail("initialize_wifi_devices: failed to create device #%d\n", device_id); + fail("initialize_wifi_devices: failed to create device #%d", device_id); // For each device, unless HWSIM_ATTR_NO_VIF is passed, a network interface is created // automatically. Such interfaces are named "wlan0", "wlan1" and so on. @@ -986,7 +986,7 @@ static void initialize_wifi_devices(void) interface[4] += device_id; if (nl80211_setup_ibss_interface(&nlmsg, sock, nl80211_family_id, interface, &ibss_props) < 0) - fail("initialize_wifi_devices: failed set up IBSS network for #%d\n", device_id); + fail("initialize_wifi_devices: failed set up IBSS network for #%d", device_id); } // Wait for all devices to join the IBSS network @@ -995,7 +995,7 @@ static void initialize_wifi_devices(void) interface[4] += device_id; int ret = await_ifla_operstate(&nlmsg, interface, IF_OPER_UP); if (ret < 0) - fail("initialize_wifi_devices: get_ifla_operstate failed for #%d, ret %d\n", device_id, ret); + fail("initialize_wifi_devices: get_ifla_operstate failed for #%d, ret %d", device_id, ret); } close(sock); @@ -2350,7 +2350,7 @@ static void rfkill_unblock_all() event.soft = 0; event.hard = 0; if (write(fd, &event, sizeof(event)) < 0) - fail("write rfkill event failed\n"); + fail("write rfkill event failed"); close(fd); } @@ -2407,7 +2407,7 @@ static bool process_command_pkt(int fd, char* buf, ssize_t buf_size) struct hci_command_hdr* hdr = (struct hci_command_hdr*)buf; if (buf_size < (ssize_t)sizeof(struct hci_command_hdr) || hdr->plen != buf_size - sizeof(struct hci_command_hdr)) { - fail("invalid size: %zx\n", buf_size); + fail("invalid size: %zx", buf_size); } switch (hdr->opcode) { diff --git a/executor/executor.cc b/executor/executor.cc index aa9f1d053..9473b871f 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -673,7 +673,7 @@ retry: break; case arg_csum_chunk_const: if (chunk_size != 2 && chunk_size != 4 && chunk_size != 8) { - fail("bad checksum const chunk size %lld\n", chunk_size); + fail("bad checksum const chunk size %lld", chunk_size); } // Here we assume that const values come to us big endian. debug_verbose("#%lld: const chunk, value: %llx, size: %llu\n", diff --git a/executor/style_test.go b/executor/style_test.go index f6f5856f3..3b0ee8ce7 100644 --- a/executor/style_test.go +++ b/executor/style_test.go @@ -110,6 +110,13 @@ if (foo) `, }, }, + { + pattern: `\s*(fail|exitf)\(".*\\n`, + message: "Don't use \\n in fail/exitf messages", + tests: []string{ + `fail("some message with new line\n");`, + }, + }, } for _, check := range checks { re := regexp.MustCompile(check.pattern) diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index d02e2732e..cdef36c54 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -1708,7 +1708,7 @@ static void initialize_tun(int tun_id) #endif if (tun_id < 0 || tun_id >= MAX_TUN) { - fail("tun_id out of range %d\n", tun_id); + fail("tun_id out of range %d", tun_id); } char tun_device[sizeof(TUN_DEVICE)]; @@ -1733,7 +1733,7 @@ static void initialize_tun(int tun_id) #endif if (tunfd == -1) { #if SYZ_EXECUTOR - fail("tun: can't open %s\n", tun_device); + fail("tun: can't open %s", tun_device); #else printf("tun: can't open %s: errno=%d\n", tun_device, errno); return; @@ -2842,7 +2842,7 @@ static void netlink_devlink_netns_move(const char* bus_name, const char* dev_nam sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) - fail("socket(AF_NETLINK) failed\n"); + fail("socket(AF_NETLINK) failed"); id = netlink_query_family_id(&nlmsg, sock, DEVLINK_FAMILY_NAME); if (id == -1) @@ -2875,7 +2875,7 @@ static void initialize_devlink_ports(const char* bus_name, const char* dev_name, int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) - fail("socket(AF_NETLINK) failed\n"); + fail("socket(AF_NETLINK) failed"); int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (rtsock == -1) @@ -3178,19 +3178,19 @@ static void initialize_wifi_devices(void) mac_addr[5] = device_id; int ret = hwsim80211_create_device(&nlmsg, sock, hwsim_family_id, mac_addr); if (ret < 0) - fail("initialize_wifi_devices: failed to create device #%d\n", device_id); + fail("initialize_wifi_devices: failed to create device #%d", device_id); char interface[6] = "wlan0"; interface[4] += device_id; if (nl80211_setup_ibss_interface(&nlmsg, sock, nl80211_family_id, interface, &ibss_props) < 0) - fail("initialize_wifi_devices: failed set up IBSS network for #%d\n", device_id); + fail("initialize_wifi_devices: failed set up IBSS network for #%d", device_id); } for (int device_id = 0; device_id < WIFI_INITIAL_DEVICE_COUNT; device_id++) { char interface[6] = "wlan0"; interface[4] += device_id; int ret = await_ifla_operstate(&nlmsg, interface, IF_OPER_UP); if (ret < 0) - fail("initialize_wifi_devices: get_ifla_operstate failed for #%d, ret %d\n", device_id, ret); + fail("initialize_wifi_devices: get_ifla_operstate failed for #%d, ret %d", device_id, ret); } close(sock); @@ -5731,7 +5731,7 @@ static void rfkill_unblock_all() event.soft = 0; event.hard = 0; if (write(fd, &event, sizeof(event)) < 0) - fail("write rfkill event failed\n"); + fail("write rfkill event failed"); close(fd); } @@ -5788,7 +5788,7 @@ static bool process_command_pkt(int fd, char* buf, ssize_t buf_size) struct hci_command_hdr* hdr = (struct hci_command_hdr*)buf; if (buf_size < (ssize_t)sizeof(struct hci_command_hdr) || hdr->plen != buf_size - sizeof(struct hci_command_hdr)) { - fail("invalid size: %zx\n", buf_size); + fail("invalid size: %zx", buf_size); } switch (hdr->opcode) { |
