don't crash when printing error messages when there are no credentials.

don't abuse the printed uid to log the inode number.

The printing/logging of error messages should be simplified.
This commit is contained in:
mlelstv 2015-08-08 08:18:52 +00:00
parent 23ac79bdb2
commit 7454f7165e
1 changed files with 18 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_alloc.c,v 1.149 2015/03/28 19:24:04 maxv Exp $ */
/* $NetBSD: ffs_alloc.c,v 1.150 2015/08/08 08:18:52 mlelstv Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.149 2015/03/28 19:24:04 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: ffs_alloc.c,v 1.150 2015/08/08 08:18:52 mlelstv Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@ -111,7 +111,7 @@ static daddr_t ffs_alloccg(struct inode *, int, daddr_t, int, int);
static daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t, int);
static ino_t ffs_dirpref(struct inode *);
static daddr_t ffs_fragextend(struct inode *, int, daddr_t, int, int);
static void ffs_fserr(struct fs *, u_int, const char *);
static void ffs_fserr(struct fs *, kauth_cred_t, const char *);
static daddr_t ffs_hashalloc(struct inode *, int, daddr_t, int, int,
daddr_t (*)(struct inode *, int, daddr_t, int, int));
static daddr_t ffs_nodealloccg(struct inode *, int, daddr_t, int, int);
@ -145,7 +145,7 @@ ffs_check_bad_allocation(const char *func, struct fs *fs, daddr_t bno,
if (bno >= fs->fs_size) {
printf("bad block %" PRId64 ", ino %llu\n", bno,
(unsigned long long)inum);
ffs_fserr(fs, inum, "bad block");
ffs_fserr(fs, NOCRED, "bad block");
return EINVAL;
}
return 0;
@ -286,7 +286,7 @@ ffs_alloc(struct inode *ip, daddr_t lbn, daddr_t bpref, int size, int flags,
}
nospace:
mutex_exit(&ump->um_lock);
ffs_fserr(fs, kauth_cred_geteuid(cred), "file system full");
ffs_fserr(fs, cred, "file system full");
uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
return (ENOSPC);
}
@ -532,7 +532,7 @@ nospace:
/*
* no space available
*/
ffs_fserr(fs, kauth_cred_geteuid(cred), "file system full");
ffs_fserr(fs, cred, "file system full");
uprintf("\n%s: write failed, file system is full\n", fs->fs_fsmnt);
return (ENOSPC);
}
@ -605,7 +605,7 @@ ffs_valloc(struct vnode *pvp, int mode, kauth_cred_t cred, ino_t *inop)
noinodes:
mutex_exit(&ump->um_lock);
UFS_WAPBL_END(pvp->v_mount);
ffs_fserr(fs, kauth_cred_geteuid(cred), "out of inodes");
ffs_fserr(fs, cred, "out of inodes");
uprintf("\n%s: create/symlink failed, no inodes free\n", fs->fs_fsmnt);
return ENOSPC;
}
@ -2159,9 +2159,17 @@ ffs_mapsearch(struct fs *fs, struct cg *cgp, daddr_t bpref, int allocsiz)
* fs: error message
*/
static void
ffs_fserr(struct fs *fs, u_int uid, const char *cp)
ffs_fserr(struct fs *fs, kauth_cred_t cred, const char *cp)
{
KASSERT(cred != NULL);
log(LOG_ERR, "uid %d, pid %d, command %s, on %s: %s\n",
uid, curproc->p_pid, curproc->p_comm, fs->fs_fsmnt, cp);
if (cred == NOCRED || cred == FSCRED) {
log(LOG_ERR, "pid %d, command %s, on %s: %s\n",
curproc->p_pid, curproc->p_comm,
fs->fs_fsmnt, cp);
} else {
log(LOG_ERR, "uid %d, pid %d, command %s, on %s: %s\n",
kauth_cred_getuid(cred), curproc->p_pid, curproc->p_comm,
fs->fs_fsmnt, cp);
}
}