char *wd;
while (true) {
std::size_t total_size = curpos + std::size_t(try_path_size);
- reppkt.resize(total_size);
if (total_size < curpos) {
- // overflow.
+ // Overflow. In theory we could now limit to size_t max, but the size must already
+ // be crazy long; let's abort.
char ack_rep[] = { DINIT_RP_NAK };
if (! queue_packet(ack_rep, 1)) return false;
return true;
}
+ reppkt.resize(total_size);
wd = getcwd(reppkt.data() + curpos, try_path_size);
if (wd != nullptr) break;
- try_path_size *= uint32_t(2u);
- if (try_path_size == 0) {
- // overflow.
+ // Keep doubling the path size we try until it's big enough, or we get numeric overflow
+ uint32_t new_try_path_size = try_path_size * uint32_t(2u);
+ if (new_try_path_size < try_path_size) {
+ // Overflow.
char ack_rep[] = { DINIT_RP_NAK };
return queue_packet(ack_rep, 1);
}
+ try_path_size = new_try_path_size;
}
uint32_t wd_len = std::strlen(reppkt.data() + curpos);
if (am_system_init) {
// setup STDIN, STDOUT, STDERR so that we can use them
int onefd = open("/dev/console", O_RDONLY, 0);
- dup2(onefd, 0);
+ if (onefd != -1) {
+ dup2(onefd, 0);
+ }
int twofd = open("/dev/console", O_RDWR, 0);
- dup2(twofd, 1);
- dup2(twofd, 2);
+ if (twofd != -1) {
+ dup2(twofd, 1);
+ dup2(twofd, 2);
+ }
if (onefd > 2) close(onefd);
if (twofd > 2) close(twofd);
char buf[1 + sizeof(handle)];
buf[0] = DINIT_CP_UNPINSERVICE;
memcpy(buf + 1, &handle, sizeof(handle));
- write_all_x(socknum, buf, 2 + sizeof(handle));
+ write_all_x(socknum, buf, sizeof(buf));
wait_for_reply(rbuffer, socknum);
if (rbuffer[0] != DINIT_RP_ACK) {
char operator[](int idx) noexcept
{
int dest_idx = cur_idx + idx;
- if (dest_idx > SIZE) dest_idx -= SIZE;
+ if (dest_idx >= SIZE) dest_idx -= SIZE;
return buf[dest_idx];
}
return r;
}
if (res < 0) {
- if (res == EINTR) {
+ if (errno == EINTR) {
continue;
}
}
// In a vector, find or create rlimits for a particular resource type.
-static service_rlimits &find_rlimits(std::vector<service_rlimits> all_rlimits, int resource_id)
+static service_rlimits &find_rlimits(std::vector<service_rlimits> &all_rlimits, int resource_id)
{
for (service_rlimits &limits : all_rlimits) {
if (limits.resource_id == resource_id) {
log(loglevel_t::WARN, "Error reading dependency directory '", depdirpath,
"' for ", servicename, " service.");
}
+
+ closedir(depdir);
}
// Check if one string starts with another