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

@ -12,6 +12,7 @@ Created: Jan 2000 by Philip Homburg <philip@cs.vu.nl>
#include <minix/com.h>
#include <minix/ds.h>
#include <minix/syslib.h>
#include <minix/param.h>
#include "pci.h"
#include <machine/pci_amd.h>

View file

@ -4,7 +4,7 @@ NOOBJ= # defined
INCSDIR= /usr/include/minix
INCS+= dirent.h paths.h types.h
INCS+= dirent.h paths.h types.h param.h
.include "${NETBSDSRCDIR}/common/include/sys/Makefile.mount.inc"
.include "${NETBSDSRCDIR}/common/include/Makefile.termios.inc"

View file

@ -72,12 +72,6 @@
#define FUTURE_CODE 0 /* new code to be activated + tested later */
#define TEMP_CODE 1 /* active code to be removed later */
/* Number of processes contained in the system image. */
#define NR_BOOT_PROCS (NR_TASKS + LAST_SPECIAL_PROC_NR + 1)
/* Process name length in the PM process table, including '\0'. */
#define PROC_NAME_LEN 16
/* Miscellaneous */
#define BYTE 0377 /* mask for 8 bits */
#define READING 0 /* copy data to user */

45
include/minix/param.h Normal file
View file

@ -0,0 +1,45 @@
#ifndef _MINIX_PARAM_H
#define _MINIX_PARAM_H 1
#include <minix/com.h>
#include <minix/const.h>
/* Number of processes contained in the system image. */
#define NR_BOOT_PROCS (NR_TASKS + LAST_SPECIAL_PROC_NR + 1)
/* This is used to obtain system information through SYS_GETINFO. */
#define MAXMEMMAP 40
typedef struct kinfo {
/* Straight multiboot-provided info */
multiboot_info_t mbi;
multiboot_module_t module_list[MULTIBOOT_MAX_MODS];
multiboot_memory_map_t memmap[MAXMEMMAP]; /* free mem list */
phys_bytes mem_high_phys;
int mmap_size;
/* Multiboot-derived */
int mods_with_kernel; /* no. of mods incl kernel */
int kern_mod; /* which one is kernel */
/* Minix stuff, started at bootstrap phase */
int freepde_start; /* lowest pde unused kernel pde */
char param_buf[MULTIBOOT_PARAM_BUF_SIZE];
/* Minix stuff */
struct kmessages *kmess;
int do_serial_debug; /* system serial output */
int serial_debug_baud; /* serial baud rate */
int minix_panicing; /* are we panicing? */
vir_bytes user_sp; /* where does kernel want stack set */
vir_bytes user_end; /* upper proc limit */
vir_bytes vir_kern_start; /* kernel addrspace starts */
vir_bytes bootstrap_start, bootstrap_len;
struct boot_image boot_procs[NR_BOOT_PROCS];
int nr_procs; /* number of user processes */
int nr_tasks; /* number of kernel tasks */
char release[6]; /* kernel release number */
char version[6]; /* kernel version number */
} kinfo_t;
#endif

View file

@ -10,9 +10,6 @@
#include <minix/types.h>
#endif
#include <minix/const.h>
#include <minix/com.h>
#include <stdint.h>
/* Type definitions. */
@ -122,6 +119,8 @@ struct mem_range
phys_bytes mr_limit; /* Highest memory address in range */
};
#define PROC_NAME_LEN 16
/* List of boot-time processes set in kernel/table.c. */
struct boot_image {
int proc_nr; /* process number to use */
@ -137,40 +136,6 @@ struct memory {
phys_bytes size;
};
/* This is used to obtain system information through SYS_GETINFO. */
#define MAXMEMMAP 40
typedef struct kinfo {
/* Straight multiboot-provided info */
multiboot_info_t mbi;
multiboot_module_t module_list[MULTIBOOT_MAX_MODS];
multiboot_memory_map_t memmap[MAXMEMMAP]; /* free mem list */
phys_bytes mem_high_phys;
int mmap_size;
/* Multiboot-derived */
int mods_with_kernel; /* no. of mods incl kernel */
int kern_mod; /* which one is kernel */
/* Minix stuff, started at bootstrap phase */
int freepde_start; /* lowest pde unused kernel pde */
char param_buf[MULTIBOOT_PARAM_BUF_SIZE];
/* Minix stuff */
struct kmessages *kmess;
int do_serial_debug; /* system serial output */
int serial_debug_baud; /* serial baud rate */
int minix_panicing; /* are we panicing? */
vir_bytes user_sp; /* where does kernel want stack set */
vir_bytes user_end; /* upper proc limit */
vir_bytes vir_kern_start; /* kernel addrspace starts */
vir_bytes bootstrap_start, bootstrap_len;
struct boot_image boot_procs[NR_BOOT_PROCS];
int nr_procs; /* number of user processes */
int nr_tasks; /* number of kernel tasks */
char release[6]; /* kernel release number */
char version[6]; /* kernel version number */
} kinfo_t;
#define STATICINIT(v, n) \
if(!(v)) { \
if(!((v) = alloc_contig(sizeof(*(v)) * (n), 0, NULL))) { \

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. */

View file

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <env.h>
#include <string.h>
#include <minix/param.h>
/*=========================================================================*
@ -98,9 +99,9 @@ struct memory *mem_chunks; /* where to store the memory bits */
int maxchunks; /* how many were found */
{
static kinfo_t kinfo;
int mm;
int mm, r;
sys_getkinfo(&kinfo);
if((r=sys_getkinfo(&kinfo)) != OK) return r;
/* Initialize everything to zero. */
memset(mem_chunks, 0, maxchunks*sizeof(*mem_chunks));

View file

@ -6,6 +6,7 @@
#include <minix/config.h>
#include <minix/ds.h>
#include <minix/bitmap.h>
#include <minix/param.h>
#include <regex.h>
#define NR_DS_KEYS (2*NR_SYS_PROCS) /* number of entries */

View file

@ -1,5 +1,7 @@
/* Global variables. */
#include <minix/param.h>
/* Parameters needed to keep diagnostics at IS. */
#define DIAG_BUF_SIZE 1024
extern char diag_buf[DIAG_BUF_SIZE]; /* buffer for messages */

View file

@ -241,7 +241,7 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
/* Set process details found in the image table. */
rmp = &mproc[ip->proc_nr];
strncpy(rmp->mp_name, ip->proc_name, PROC_NAME_LEN);
strlcpy(rmp->mp_name, ip->proc_name, PROC_NAME_LEN);
(void) sigemptyset(&rmp->mp_ignore);
(void) sigemptyset(&rmp->mp_sigmask);
(void) sigemptyset(&rmp->mp_catch);

View file

@ -16,6 +16,7 @@
#include <minix/syslib.h>
#include <minix/sysutil.h>
#include <minix/timers.h>
#include <minix/param.h>
#include <limits.h>
#include <errno.h>

View file

@ -1,6 +1,8 @@
#ifndef _PROCFS_GLO_H
#define _PROCFS_GLO_H
#include <minix/param.h>
/* pid.c */
extern struct file pid_files[];

View file

@ -8,6 +8,8 @@
#define EXTERN
#endif
#include <minix/param.h>
/* The boot image priv table. This table has entries for all system
* services in the boot image.
*/

View file

@ -7,6 +7,8 @@
#define EXTERN
#endif
#include <minix/param.h>
/* File System global variables */
EXTERN struct fproc *fp; /* pointer to caller's fproc struct */
EXTERN int susp_count; /* number of procs suspended on pipe */

View file

@ -522,7 +522,7 @@ int pt_map_in_range(struct vmproc *src_vmp, struct vmproc *dst_vmp,
end = end ? end : VM_DATATOP;
assert(start % I386_PAGE_SIZE == 0);
assert(end % I386_PAGE_SIZE == 0);
assert(I386_VM_PDE(start) >= 0 && start <= end);
assert(start <= end);
assert(I386_VM_PDE(end) < I386_VM_DIR_ENTRIES);
#if LU_DEBUG

View file

@ -1,6 +1,7 @@
#include <minix/sys_config.h>
#include <minix/type.h>
#include <minix/param.h>
#include <sys/stat.h>
#include <a.out.h>
#include <tools.h>

View file

@ -276,7 +276,7 @@ void exec_bootproc(struct vmproc *vmp, struct boot_image *ip)
execi->proc_e = vmp->vm_endpoint;
execi->hdr = hdr;
execi->hdr_len = sizeof(hdr);
strcpy(execi->progname, ip->proc_name);
strlcpy(execi->progname, ip->proc_name, sizeof(execi->progname));
execi->frame_len = 0;
execi->opaque = &vmexeci;
@ -371,8 +371,9 @@ void init_vm(void)
/* Set up table of calls. */
#define CALLMAP(code, func) { int i; \
if((i=CALLNUMBER(code)) < 0) { panic(#code " invalid: %d", (code)); } \
if(i >= NR_VM_CALLS) { panic(#code " invalid: %d", (code)); } \
i=CALLNUMBER(code); \
assert(i >= 0); \
assert(i < NR_VM_CALLS); \
vm_calls[i].vmc_func = (func); \
vm_calls[i].vmc_name = #code; \
}