svn commit: r250223 - in head: lib/libprocstat sys/kern sys/sys usr.bin/fstat

Mikolaj Golub trociny at FreeBSD.org
Sat May 4 18:54:31 UTC 2013


On Fri, May 03, 2013 at 09:11:57PM +0000, John Baldwin wrote:

> +static int
> +procstat_get_sem_info_kvm(kvm_t *kd, struct filestat *fst,
> +    struct semstat *sem, char *errbuf)
> +{
> +	struct ksem ksem;
> +	void *ksemp;
> +	char *path;
> +	int i;
> +
> +	assert(kd);
> +	assert(sem);
> +	assert(fst);
> +	bzero(sem, sizeof(*sem));
> +	ksemp = fst->fs_typedep;
> +	if (ksemp == NULL)
> +		goto fail;
> +	if (!kvm_read_all(kd, (unsigned long)ksemp, &ksem,
> +	    sizeof(struct ksem))) {
> +		warnx("can't read ksem at %p", (void *)ksemp);
> +		goto fail;
> +	}
> +	sem->mode = S_IFREG | ksem.ks_mode;
> +	sem->value = ksem.ks_value;
> +	if (fst->fs_path == NULL && ksem.ks_path != NULL) {
> +		path = malloc(MAXPATHLEN);
> +		for (i = 0; i < MAXPATHLEN - 1; i++) {
> +			if (!kvm_read_all(kd, (unsigned long)ksem.ks_path + i,
> +			    path + i, 1))
> +				break;
> +			if (path[i] == '\0')
> +				break;
> +		}
> +		path[i] = '\0';
> +		if (i == 0)
> +			free(path);
> +		else
> +			fst->fs_path = path;
> +	}
> +	return (0);
> +
> +fail:
> +	snprintf(errbuf, _POSIX2_LINE_MAX, "error");
> +	return (1);
> +}

I would like to make errbuf optional (for all libprocstat functions
that provide it) adding a check before printing to errbuf:

  if (errbuf != NULL)
  	snprintf(errbuf, ...

It looks like there are callers who are not interested in errbuf
content. E.g. currently procstat(1) passes NULL when calling functions
that require errbuf, namely procstat_get_socket_info and
procstat_get_vnode_info, potentially crashing here if an error occurs.

Do you (anyone) have objections?

-- 
Mikolaj Golub


More information about the svn-src-all mailing list