Date: Sat, 4 May 2013 21:54:20 +0300 From: Mikolaj Golub <trociny@FreeBSD.org> To: John Baldwin <jhb@FreeBSD.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r250223 - in head: lib/libprocstat sys/kern sys/sys usr.bin/fstat Message-ID: <20130504185419.GA32075@gmail.com> In-Reply-To: <201305032111.r43LBvZ3040508@svn.freebsd.org> References: <201305032111.r43LBvZ3040508@svn.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130504185419.GA32075>