From: <da...@us...> - 2002-11-22 17:33:36
|
Update of /cvsroot/cerber/cerb-ng/kcerb In directory sc8-pr-cvs1:/tmp/cvs-serv25522 Modified Files: cerb_action.c cerb_rules.c cerb_string.c Log Message: - Removed memory leak - registers wasn't cleared on module unload. - fcb_op_realpath() should set v_size! - When somethings goes wrong with realpath() then string "[none]" is returned. - fcb_getval() should set v_type!! - Simplify fcb_getval(). - When NULL pointer is given as string for fcb_vprintf(), then string "[empty]" is returned. Index: cerb_action.c =================================================================== RCS file: /cvsroot/cerber/cerb-ng/kcerb/cerb_action.c,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** cerb_action.c 21 Nov 2002 00:42:35 -0000 1.36 --- cerb_action.c 22 Nov 2002 17:33:28 -0000 1.37 *************** *** 388,392 **** val->v_type != CB_DEF_T && val->v_type != CB_UDEF_T) { ! MCB_XDEBUG(EINVAL, "Invalid argument %u type.", i); } --- 388,392 ---- val->v_type != CB_DEF_T && val->v_type != CB_UDEF_T) { ! MCB_XDEBUG(EINVAL, "Invalid argument 0 type: %u.", val->v_type); } *************** *** 549,552 **** --- 549,553 ---- fcb_op_realpath(CB_OPARGS) { + static char none[] = "[none]"; int error; *************** *** 563,570 **** fcb_mtemp_add(retv->v_str); error = fcb_realpath(p, v[0]->v_str, retv->v_str, MAXPATHLEN); ! if (error == 0) { ! retv->v_id = ECB_CONST_I; ! retv->v_type = CB_STR_T; ! } return (error); --- 564,573 ---- fcb_mtemp_add(retv->v_str); error = fcb_realpath(p, v[0]->v_str, retv->v_str, MAXPATHLEN); ! if (error != 0) ! retv->v_str = none; ! ! retv->v_id = ECB_CONST_I; ! retv->v_type = CB_STR_T; ! retv->v_size = strlen(retv->v_str) + 1; return (error); Index: cerb_rules.c =================================================================== RCS file: /cvsroot/cerber/cerb-ng/kcerb/cerb_rules.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** cerb_rules.c 21 Nov 2002 00:42:35 -0000 1.24 --- cerb_rules.c 22 Nov 2002 17:33:29 -0000 1.25 *************** *** 55,59 **** for (i = 0; i < CB_NREGS_G; ++i) { tcb_regs[i].v_id = ECB_EMPTY_I; ! tcb_regs[i].v_type = 0; tcb_regs[i].v_val = 0; } --- 55,59 ---- for (i = 0; i < CB_NREGS_G; ++i) { tcb_regs[i].v_id = ECB_EMPTY_I; ! tcb_regs[i].v_type = CB_EMPTY_T; tcb_regs[i].v_val = 0; } *************** *** 95,98 **** --- 95,100 ---- MCB_FREE(tcb_tabs[i].t_rules); } + for (i = 0; i < CB_NREGS_G; ++i) + fcb_regfree(i); } *************** *** 153,161 **** --- 155,166 ---- if (v->v_id != ECB_LOCAL_I) { retv->v_val = v->v_val; + retv->v_type = v->v_type; retv->v_size = v->v_size; return (0); } + /* Those values are most often. */ retv->v_size = 0; + retv->v_type = CB_UDEF_T; switch(v->v_nloc) { *************** *** 166,169 **** --- 171,175 ---- retv->v_str = p->p_comm; retv->v_size = strlen(p->p_comm) + 1; + retv->v_type = CB_STR_T; return (0); case ECB_PID_L: *************** *** 193,274 **** case ECB_GROUPS_L: retv->v_uvalp = p->p_ucred->cr_groups; retv->v_size = p->p_ucred->cr_ngroups; return (0); case ECB_LOGIN_L: retv->v_str = p->p_session->s_login; retv->v_size = strlen(p->p_session->s_login) + 1; return (0); case ECB_PRISON_L: retv->v_ptr = p->p_prison; retv->v_size = sizeof (struct prison); return (0); case ECB_RETVAL0_L: retv->v_val = p->p_retval[0]; return (0); case ECB_RETVAL1_L: retv->v_val = p->p_retval[1]; return (0); case ECB_FNAME_L: /* Name of executalbe will be process name for now. */ retv->v_str = p->p_comm; retv->v_size = strlen(p->p_comm) + 1; return (0); ! case ECB_FINODE_L: ! if ((error = VOP_GETATTR(p->p_textvp, &va, ! p->p_ucred, p)) == 0) { ! retv->v_uval = va.va_fileid; ! return (0); ! } return (error); case ECB_FDEV_L: ! if ((error = VOP_GETATTR(p->p_textvp, &va, ! p->p_ucred, p)) == 0) { ! retv->v_uval = va.va_fsid; ! return (0); ! } ! return (error); case ECB_FUID_L: ! if ((error = VOP_GETATTR(p->p_textvp, &va, ! p->p_ucred, p)) == 0) { ! retv->v_uval = va.va_uid; ! return (0); ! } ! return (error); case ECB_FGID_L: ! if ((error = VOP_GETATTR(p->p_textvp, &va, ! p->p_ucred, p)) == 0) { ! retv->v_uval = va.va_gid; ! return (0); ! } ! return (error); case ECB_FMODE_L: ! if ((error = VOP_GETATTR(p->p_textvp, &va, ! p->p_ucred, p)) == 0) { ! retv->v_uval = va.va_mode; ! return (0); ! } ! return (error); case ECB_FFLAGS_L: ! if ((error = VOP_GETATTR(p->p_textvp, &va, ! p->p_ucred, p)) == 0) { ! retv->v_uval = va.va_flags; ! return (0); ! } ! return (error); case ECB_FNLINKS_L: ! if ((error = VOP_GETATTR(p->p_textvp, &va, ! p->p_ucred, p)) == 0) { ! retv->v_uval = va.va_nlink; ! return (0); ! } ! return (error); case ECB_FSIZE_L: ! if ((error = VOP_GETATTR(p->p_textvp, &va, ! p->p_ucred, p)) == 0) { ! retv->v_uval = va.va_size; ! return (0); ! } ! return (error); default: return (EINVAL); } --- 199,270 ---- case ECB_GROUPS_L: retv->v_uvalp = p->p_ucred->cr_groups; + retv->v_type = CB_UDEFPTR_T; retv->v_size = p->p_ucred->cr_ngroups; return (0); case ECB_LOGIN_L: retv->v_str = p->p_session->s_login; + retv->v_type = CB_STR_T; retv->v_size = strlen(p->p_session->s_login) + 1; return (0); case ECB_PRISON_L: retv->v_ptr = p->p_prison; + retv->v_type = CB_PTR_T; retv->v_size = sizeof (struct prison); return (0); case ECB_RETVAL0_L: retv->v_val = p->p_retval[0]; + retv->v_type = CB_DEF_T; return (0); case ECB_RETVAL1_L: retv->v_val = p->p_retval[1]; + retv->v_type = CB_DEF_T; return (0); case ECB_FNAME_L: /* Name of executalbe will be process name for now. */ retv->v_str = p->p_comm; + retv->v_type = CB_STR_T; retv->v_size = strlen(p->p_comm) + 1; return (0); ! } ! ! if (v->v_nloc >= ECB_MAXLOCAL_L) { ! retv->v_type = CB_UNKNOWN_T; ! return (EINVAL); ! } ! ! error = VOP_GETATTR(p->p_textvp, &va, p->p_ucred, p); ! if (error != 0) { ! retv->v_type = CB_UNKNOWN_T; return (error); + } + + switch(v->v_nloc) { + case ECB_FINODE_L: + retv->v_uval = va.va_fileid; + return (0); case ECB_FDEV_L: ! retv->v_uval = va.va_fsid; ! return (0); case ECB_FUID_L: ! retv->v_uval = va.va_uid; ! return (0); case ECB_FGID_L: ! retv->v_uval = va.va_gid; ! return (0); case ECB_FMODE_L: ! retv->v_uval = va.va_mode; ! return (0); case ECB_FFLAGS_L: ! retv->v_uval = va.va_flags; ! return (0); case ECB_FNLINKS_L: ! retv->v_uval = va.va_nlink; ! return (0); case ECB_FSIZE_L: ! retv->v_uval = va.va_size; ! return (0); default: + /* NOTREACHED */ + retv->v_type = CB_UNKNOWN_T; return (EINVAL); } Index: cerb_string.c =================================================================== RCS file: /cvsroot/cerber/cerb-ng/kcerb/cerb_string.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** cerb_string.c 26 Sep 2002 21:55:52 -0000 1.7 --- cerb_string.c 22 Nov 2002 17:33:29 -0000 1.8 *************** *** 416,422 **** fcb_vprintf_str(char *buf, size_t size, register u_int pos, register char *str) { ! for (; pos < size && *str != '\0'; ++pos, ++str) ! buf[pos] = *str; return (pos); --- 416,429 ---- fcb_vprintf_str(char *buf, size_t size, register u_int pos, register char *str) { + static char empty[] = "[empty]"; + char *instr; ! if (str == NULL) ! instr = empty; ! else ! instr = str; ! ! for (; pos < size && *instr != '\0'; ++pos, ++instr) ! buf[pos] = *instr; return (pos); |