Merge pull request #7943 from yuwata/fix-chase_symlinks
fs-util: use `_cleanup_close_` attribute
This commit is contained in:
commit
47925d7f32
|
@ -730,7 +730,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
|
||||||
/* Two dots? Then chop off the last bit of what we already found out. */
|
/* Two dots? Then chop off the last bit of what we already found out. */
|
||||||
if (path_equal(first, "/..")) {
|
if (path_equal(first, "/..")) {
|
||||||
_cleanup_free_ char *parent = NULL;
|
_cleanup_free_ char *parent = NULL;
|
||||||
int fd_parent = -1;
|
_cleanup_close_ int fd_parent = -1;
|
||||||
|
|
||||||
/* If we already are at the top, then going up will not change anything. This is in-line with
|
/* If we already are at the top, then going up will not change anything. This is in-line with
|
||||||
* how the kernel handles this. */
|
* how the kernel handles this. */
|
||||||
|
@ -765,6 +765,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
|
||||||
|
|
||||||
safe_close(fd);
|
safe_close(fd);
|
||||||
fd = fd_parent;
|
fd = fd_parent;
|
||||||
|
fd_parent = -1;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -833,8 +834,6 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
free(done);
|
|
||||||
|
|
||||||
if (flags & CHASE_SAFE) {
|
if (flags & CHASE_SAFE) {
|
||||||
if (fstat(fd, &st) < 0)
|
if (fstat(fd, &st) < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
@ -845,6 +844,8 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
|
||||||
previous_stat = st;
|
previous_stat = st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(done);
|
||||||
|
|
||||||
/* Note that we do not revalidate the root, we take it as is. */
|
/* Note that we do not revalidate the root, we take it as is. */
|
||||||
if (isempty(root))
|
if (isempty(root))
|
||||||
done = NULL;
|
done = NULL;
|
||||||
|
|
|
@ -62,7 +62,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
server->bound_leases[pool_offset] = lease;
|
server->bound_leases[pool_offset] = lease;
|
||||||
assert_se(hashmap_put(server->leases_by_client_id, &lease->client_id, lease) >= 0);
|
assert_se(hashmap_put(server->leases_by_client_id, &lease->client_id, lease) >= 0);
|
||||||
|
|
||||||
dhcp_server_handle_message(server, (DHCPMessage*)data, size);
|
(void) dhcp_server_handle_message(server, (DHCPMessage*)data, size);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,23 +21,20 @@
|
||||||
|
|
||||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
_cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
|
_cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
|
||||||
int r;
|
|
||||||
|
|
||||||
if (size > DNS_PACKET_SIZE_MAX)
|
if (size > DNS_PACKET_SIZE_MAX)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
r = dns_packet_new(&p, DNS_PROTOCOL_DNS, 0, DNS_PACKET_SIZE_MAX);
|
assert_se(dns_packet_new(&p, DNS_PROTOCOL_DNS, 0, DNS_PACKET_SIZE_MAX) >= 0);
|
||||||
if (r < 0)
|
|
||||||
return 0;
|
|
||||||
p->size = 0; /* by default append starts after the header, undo that */
|
p->size = 0; /* by default append starts after the header, undo that */
|
||||||
dns_packet_append_blob(p, data, size, NULL);
|
assert_se(dns_packet_append_blob(p, data, size, NULL) >= 0);
|
||||||
if (size < DNS_PACKET_HEADER_SIZE) {
|
if (size < DNS_PACKET_HEADER_SIZE) {
|
||||||
/* make sure we pad the packet back up to the minimum header size */
|
/* make sure we pad the packet back up to the minimum header size */
|
||||||
assert(p->allocated >= DNS_PACKET_HEADER_SIZE);
|
assert_se(p->allocated >= DNS_PACKET_HEADER_SIZE);
|
||||||
memzero(DNS_PACKET_DATA(p) + size, DNS_PACKET_HEADER_SIZE - size);
|
memzero(DNS_PACKET_DATA(p) + size, DNS_PACKET_HEADER_SIZE - size);
|
||||||
p->size = DNS_PACKET_HEADER_SIZE;
|
p->size = DNS_PACKET_HEADER_SIZE;
|
||||||
}
|
}
|
||||||
dns_packet_extract(p);
|
(void) dns_packet_extract(p);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
printf("%s... ", name);
|
printf("%s... ", name);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
(void)LLVMFuzzerTestOneInput((uint8_t*)buf, size);
|
(void) LLVMFuzzerTestOneInput((uint8_t*)buf, size);
|
||||||
printf("ok\n");
|
printf("ok\n");
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -949,7 +949,7 @@ static int client_parse_message(
|
||||||
pos += sizeof(*option) + optlen;
|
pos += sizeof(*option) + optlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r < 0 || !clientid) {
|
if (!clientid) {
|
||||||
log_dhcp6_client(client, "%s has incomplete options",
|
log_dhcp6_client(client, "%s has incomplete options",
|
||||||
dhcp6_message_type_to_string(message->type));
|
dhcp6_message_type_to_string(message->type));
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -89,7 +89,9 @@ int main(int argc, char *argv[]) {
|
||||||
assert_se(sd_resolve_default(&resolve) >= 0);
|
assert_se(sd_resolve_default(&resolve) >= 0);
|
||||||
|
|
||||||
/* Test a floating resolver query */
|
/* Test a floating resolver query */
|
||||||
sd_resolve_getaddrinfo(resolve, NULL, "redhat.com", "http", NULL, getaddrinfo_handler, NULL);
|
r = sd_resolve_getaddrinfo(resolve, NULL, "redhat.com", "http", NULL, getaddrinfo_handler, NULL);
|
||||||
|
if (r < 0)
|
||||||
|
log_error_errno(r, "sd_resolve_getaddrinfo(): %m");
|
||||||
|
|
||||||
/* Make a name -> address query */
|
/* Make a name -> address query */
|
||||||
r = sd_resolve_getaddrinfo(resolve, &q1, argc >= 2 ? argv[1] : "www.heise.de", NULL, &hints, getaddrinfo_handler, NULL);
|
r = sd_resolve_getaddrinfo(resolve, &q1, argc >= 2 ? argv[1] : "www.heise.de", NULL, &hints, getaddrinfo_handler, NULL);
|
||||||
|
|
Loading…
Reference in a new issue