various coverity-inspired fixes

. some strncpy/strcpy to strlcpy conversions
	. new <minix/param.h> to avoid including other minix headers
	  that have colliding definitions with library and commands code,
	  causing parse warnings
	. removed some dead code / assignments
This commit is contained in:
Ben Gras
2012-07-16 13:17:11 +02:00
parent 77dbd766c1
commit cbcdb838f1
26 changed files with 89 additions and 80 deletions

View File

@@ -746,7 +746,7 @@ void memory_init(void)
void arch_proc_init(struct proc *pr, const u32_t ip, const u32_t sp, char *name)
{
arch_proc_reset(pr);
strcpy(pr->p_name, name);
strlcpy(pr->p_name, name, sizeof(pr->p_name));
/* set custom state we know */
pr->p_reg.pc = ip;

View File

@@ -1,15 +1,13 @@
#include <minix/cpufeature.h>
#include <minix/type.h>
#include <libexec.h>
#include <assert.h>
#include "kernel.h"
#include <libexec.h>
#include "arch_proto.h"
#include <string.h>
#include <libexec.h>
#include <minix/type.h>
/* These are set/computed in kernel.lds. */
extern char _kern_vir_base, _kern_phys_base, _kern_size;
@@ -174,11 +172,11 @@ void pg_identity(kinfo_t *cbi)
for(i = 0; i < I386_VM_DIR_ENTRIES; i++) {
u32_t flags = I386_VM_PRESENT | I386_VM_BIGPAGE |
I386_VM_USER | I386_VM_WRITE;
phys = i * I386_BIG_PAGE_SIZE;
if((cbi->mem_high_phys & I386_VM_ADDR_MASK_4MB)
<= (phys & I386_VM_ADDR_MASK_4MB)) {
flags |= I386_VM_PWT | I386_VM_PCD;
}
phys = i * I386_BIG_PAGE_SIZE;
pagedir[i] = phys | flags;
}
}

View File

@@ -364,7 +364,7 @@ void arch_boot_proc(struct boot_image *ip, struct proc *rp)
execi.proc_e = ip->endpoint;
execi.hdr = (char *) mod->mod_start; /* phys mem direct */
execi.hdr_len = mod->mod_end - mod->mod_start;
strcpy(execi.progname, ip->proc_name);
strlcpy(execi.progname, ip->proc_name, sizeof(execi.progname));
execi.frame_len = 0;
/* callbacks for use in the kernel */

View File

@@ -34,6 +34,7 @@
#include <timers.h> /* watchdog timer management */
#include <errno.h> /* return codes and error numbers */
#include <sys/param.h>
#include <minix/param.h>
/* Important kernel header files. */
#include "config.h" /* configuration, MUST be first */

View File

@@ -201,7 +201,8 @@ void kmain(kinfo_t *local_cbi)
kcalls = TSK_KC; /* allowed kernel calls */
}
/* Priviliges for the root system process. */
else if(isrootsysn(proc_nr)) {
else {
assert(isrootsysn(proc_nr));
priv(rp)->s_flags= RSYS_F; /* privilege flags */
priv(rp)->s_trap_mask= SRV_T; /* allowed traps */
ipc_to_m = SRV_M; /* allowed targets */
@@ -210,10 +211,6 @@ void kmain(kinfo_t *local_cbi)
rp->p_priority = SRV_Q; /* priority queue */
rp->p_quantum_size_ms = SRV_QT; /* quantum size */
}
/* Priviliges for ordinary process. */
else {
NOT_REACHABLE;
}
/* Fill in target mask. */
memset(&map, 0, sizeof(map));
@@ -394,10 +391,8 @@ void cstart()
/* Record miscellaneous information for user-space servers. */
kinfo.nr_procs = NR_PROCS;
kinfo.nr_tasks = NR_TASKS;
strncpy(kinfo.release, OS_RELEASE, sizeof(kinfo.release));
kinfo.release[sizeof(kinfo.release)-1] = '\0';
strncpy(kinfo.version, OS_VERSION, sizeof(kinfo.version));
kinfo.version[sizeof(kinfo.version)-1] = '\0';
strlcpy(kinfo.release, OS_RELEASE, sizeof(kinfo.release));
strlcpy(kinfo.version, OS_VERSION, sizeof(kinfo.version));
/* Load average data initialization. */
kloadinfo.proc_last_slot = 0;

View File

@@ -30,11 +30,9 @@
*/
#include <minix/com.h>
#include <minix/endpoint.h>
#include <minix/ipcconst.h>
#include <stddef.h>
#include <signal.h>
#include <minix/syslib.h>
#include <assert.h>
#include "debug.h"
@@ -47,6 +45,8 @@
#include "arch_proto.h"
#include <minix/syslib.h>
/* Scheduling and message passing functions */
static void idle(void);
/**

View File

@@ -17,12 +17,13 @@
#include <minix/config.h>
#include <minix/profile.h>
#include <minix/portio.h>
#include "kernel.h"
#include "profile.h"
#include "proc.h"
#include <minix/profile.h>
#include <minix/portio.h>
#if SPROFILE
#include <string.h>

View File

@@ -10,7 +10,6 @@
*/
#include <string.h>
#include <minix/endpoint.h>
#include "kernel/system.h"

View File

@@ -14,10 +14,9 @@
*/
#include <assert.h>
#include <minix/type.h>
#include <minix/safecopies.h>
#include "kernel/system.h"
#include "kernel.h"
#define MAX_INDIRECT_DEPTH 5 /* up to how many indirect grants to follow? */

View File

@@ -12,11 +12,10 @@
#include <assert.h>
#include <minix/type.h>
#include <minix/type.h>
#include <minix/safecopies.h>
#include "kernel/system.h"
#include "kernel.h"
#include <minix/safecopies.h>
#include <signal.h>
@@ -119,9 +118,8 @@ int map_invoke_vm(struct proc * caller,
endpoint_t end_s, vir_bytes off_s,
size_t size, int flag)
{
struct proc *src, *dst;
struct proc *dst;
src = endpoint_lookup(end_s);
dst = endpoint_lookup(end_d);
/* Make sure the linear addresses are both page aligned. */