diff --git a/app/AppDelegate.m b/app/AppDelegate.m index e36790218f..82e8023880 100644 --- a/app/AppDelegate.m +++ b/app/AppDelegate.m @@ -153,6 +153,8 @@ - (intptr_t)boot { generic_mkdirat(AT_PWD, "/run", 0755); generic_unlinkat(AT_PWD, "/var/run"); generic_symlinkat("/run", AT_PWD, "/var/run"); + // The following would be a better solution for /var/run, but tmpfs is currently broken + //do_mount(&tmpfs, "run", "/run", "", 0); // Create directories/links to simulate /sys stuff for battery monitoring generic_mkdirat(AT_PWD, "/sys/class", 0755); diff --git a/app/PasteboardDevice.m b/app/PasteboardDevice.m index d6bfb6c1c9..fb393e167a 100644 --- a/app/PasteboardDevice.m +++ b/app/PasteboardDevice.m @@ -109,7 +109,7 @@ static ssize_t clipboard_read_sync(clip_fd *fd) { } @autoreleasepool { - size_t len; + size_t len = 0; const void *data = get_data(fd, &len); // Make sure size is still INITIAL_BUFFER_CAP based diff --git a/fs/fake.c b/fs/fake.c index f3b1ce688d..26de76ef71 100644 --- a/fs/fake.c +++ b/fs/fake.c @@ -359,7 +359,7 @@ static int fakefs_mount(struct mount *mount) { strncpy(db_path, mount->source, PATH_MAX -1); char *basename = strrchr(db_path, '/') + 1; assert(strcmp(basename, "data") == 0); - strncpy(basename, "meta.db", 8); + strlcpy(basename, "meta.db", 8); // do this now so rebuilding can use root_fd int err = realfs.mount(mount); diff --git a/fs/lock.c b/fs/lock.c index f8f09e64cd..171c1426ac 100644 --- a/fs/lock.c +++ b/fs/lock.c @@ -39,7 +39,7 @@ static struct file_lock *file_lock_copy(struct file_lock *request) { lock->type = request->type; lock->owner = request->owner; lock->pid = request->pid; - strncpy(lock->comm, request->comm, 16); + strlcpy(lock->comm, request->comm, 16); list_init(&lock->locks); return lock; } @@ -176,7 +176,7 @@ static int file_lock_from_flock(struct fd *fd, struct flock_ *flock, struct file lock->type = flock->type; lock->owner = current->files; lock->pid = current->pid; - strncpy(lock->comm, current->comm, 16); + strlcpy(lock->comm, current->comm, 16); return 0; } @@ -189,7 +189,7 @@ static int flock_from_file_lock(struct file_lock *lock, struct flock_ *flock) { else flock->len = 0; flock->pid = lock->pid; - strncpy(lock->comm, flock->comm, 16); + strlcpy(lock->comm, flock->comm, 16); return 0; } diff --git a/fs/proc/ish.c b/fs/proc/ish.c index e2ebe5ced0..d901d201fe 100644 --- a/fs/proc/ish.c +++ b/fs/proc/ish.c @@ -166,7 +166,7 @@ char *get_ip_str(const struct sockaddr *sa, char *s, socklen_t maxlen) { break; default: - strncpy(s, "Unknown AF", maxlen); + strlcpy(s, "Unknown AF", maxlen); return NULL; } @@ -204,7 +204,7 @@ char *parse_if_flags(int flags) { {IFF_MULTICAST, "MULTICAST"}, }; - for (int i = 0; i < sizeof(flag_str_map)/sizeof(flag_str_map[0]); ++i) { + for (unsigned long i = 0; i < sizeof(flag_str_map)/sizeof(flag_str_map[0]); ++i) { if (flags & flag_str_map[i].flag) { if (!first) { strcat(build_string, ","); @@ -235,9 +235,9 @@ static int proc_ish_show_ips(struct proc_entry *UNUSED(entry), struct proc_data char int_dstaddr[100]; if (cursor->ifa_addr->sa_family == AF_INET) { - strncpy(type, "IF_INET", sizeof(type)); + strlcpy(type, "IF_INET", sizeof(type)); } else { - strncpy(type, "IF_INET6", sizeof(type)); + strlcpy(type, "IF_INET6", sizeof(type)); } type[sizeof(type) - 1] = '\0'; @@ -250,7 +250,7 @@ static int proc_ish_show_ips(struct proc_entry *UNUSED(entry), struct proc_data } char int_flags[250]; - strncpy(int_flags, parse_if_flags(cursor->ifa_flags), sizeof(int_flags)); + strlcpy(int_flags, parse_if_flags(cursor->ifa_flags), sizeof(int_flags)); int_flags[sizeof(int_flags) - 1] = '\0'; proc_printf(buf, "%-10.10s %-40s %-40s %-8s %-60s\n", diff --git a/fs/sock.c b/fs/sock.c index 9dcccffc54..1e5872e08d 100644 --- a/fs/sock.c +++ b/fs/sock.c @@ -79,7 +79,7 @@ static struct fd *sock_getfd(fd_t sock_fd) { return sock; } -static uint32_t unix_socket_next_id() { +static uint32_t unix_socket_next_id(void) { static uint32_t next_id = 0; static lock_t next_id_lock = LOCK_INITIALIZER; lock(&next_id_lock, 0); diff --git a/kernel/exec.c b/kernel/exec.c index 724108ad08..06000ef71d 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -605,7 +605,7 @@ int __do_execve(const char *file, struct exec_args argv, struct exec_args envp) basename = file; else basename++; - strncpy(current->comm, basename, sizeof(current->comm)); + strlcpy(current->comm, basename, sizeof(current->comm)); unlock(¤t->general_lock); update_thread_name(); diff --git a/kernel/log.c b/kernel/log.c index 8e16c076a7..7c16231b5b 100644 --- a/kernel/log.c +++ b/kernel/log.c @@ -267,7 +267,7 @@ char * current_comm(void) { static char comm[16]; if(current != NULL) { if(strcmp(current->comm, "")) { - strncpy(comm, current->comm, 16); + strlcpy(comm, current->comm, 16); } else { return ""; } diff --git a/util/sync.h b/util/sync.h index b40702e4ee..0f96cdc7ec 100644 --- a/util/sync.h +++ b/util/sync.h @@ -175,14 +175,14 @@ static inline void __lock(lock_t *lock, int log_lock, __attribute__((unused)) co lock->owner = pthread_self(); lock->pid = current_pid(); lock->uid = current_uid(); - strncpy(lock->comm, current_comm(), 16); + strlcpy(lock->comm, current_comm(), 16); modify_critical_region_counter_wrapper(-1, __FILE__, __LINE__); } else { pthread_mutex_lock(&lock->m); lock->owner = pthread_self(); lock->pid = current_pid(); lock->uid = current_uid(); - strncpy(lock->comm, current_comm(), 16); + strlcpy(lock->comm, current_comm(), 16); } return; } @@ -343,7 +343,7 @@ static inline void __write_lock(wrlock_t *lock, const char *file, int line) { // lock->line = line; lock->pid = current_pid(); if(lock->pid > 9) - strncpy((char *)lock->comm, current_comm(), 16); + strlcpy((char *)lock->comm, current_comm(), 16); //STRACE("write_lock(%x, %s(%d), %s, %d\n", lock, lock->comm, lock->pid, file, line); } @@ -370,7 +370,7 @@ static inline int trylockw(wrlock_t *lock, __attribute__((unused)) const char *f modify_locks_held_count_wrapper(1); //STRACE("trylockw(%x, %s(%d), %s, %d\n", lock, lock->comm, lock->pid, file, line); lock->pid = current_pid(); - strncpy(lock->comm, current_comm(), 16); + strlcpy(lock->comm, current_comm(), 16); } return status; } @@ -395,7 +395,7 @@ static inline int trylock(lock_t *lock, __attribute__((unused)) const char *file //STRACE("trylock(%x, %s(%d), %s, %d\n", lock, lock->comm, lock->pid, file, line); lock->pid = current_pid(); - strncpy(lock->comm, current_comm(), 16); + strlcpy(lock->comm, current_comm(), 16); } return status; } @@ -499,7 +499,7 @@ static inline void _read_lock(wrlock_t *lock, __attribute__((unused)) const char lock->pid = current_pid(); if(lock->pid > 9) - strncpy((char *)lock->comm, current_comm(), 16); + strlcpy((char *)lock->comm, current_comm(), 16); modify_critical_region_counter_wrapper(-1, __FILE__, __LINE__); //STRACE("read_lock(%d, %s(%d), %s, %d\n", lock, lock->comm, lock->pid, file, line); }