From owner-svn-src-all@FreeBSD.ORG Sat May 4 18:54:31 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id D98AF1B2; Sat, 4 May 2013 18:54:31 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-ee0-f43.google.com (mail-ee0-f43.google.com [74.125.83.43]) by mx1.freebsd.org (Postfix) with ESMTP id ED5F5AAA; Sat, 4 May 2013 18:54:30 +0000 (UTC) Received: by mail-ee0-f43.google.com with SMTP id b15so1222069eek.2 for ; Sat, 04 May 2013 11:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=eblBClD65oIY+6oG6qcWfJbs3zzvdjGTqP0pX8SMMkE=; b=h7dvl/xO3h2twape04jnfPcI9pMhWCBlB8g9lwkuPCOdJjA1rbuLmbU1YsFkXI6OYD KE3FrIhRjRwaC4OatXoxZEZNbcFFu+sbUbxISCvircwuVZR/hTH7p0/bbImwXy+1gAl2 ttr37Ia5PSPpEgB/SXYhjk8ZbmWjLYicdwijtj+eIS9m1BMbJBPunWSIqaFgGILyHwyh 5CttxDGD7gTmqQneV9neEy3TCAAGwb9eYQxj+XzfkacnEKlKd6nqgFFoQ/Kp3ZHnVb7k IGkwpqHoMq/pLR8rODJXifQISKQRNc92Ck6Su6B8gYA3OfKMnMOv64odbFdiHikfuyQ5 iylA== X-Received: by 10.14.127.5 with SMTP id c5mr26733377eei.45.1367693663755; Sat, 04 May 2013 11:54:23 -0700 (PDT) Received: from localhost ([178.150.115.244]) by mx.google.com with ESMTPSA id bn53sm23205068eeb.7.2013.05.04.11.54.21 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 04 May 2013 11:54:22 -0700 (PDT) Sender: Mikolaj Golub Date: Sat, 4 May 2013 21:54:20 +0300 From: Mikolaj Golub To: John Baldwin Subject: Re: svn commit: r250223 - in head: lib/libprocstat sys/kern sys/sys usr.bin/fstat Message-ID: <20130504185419.GA32075@gmail.com> References: <201305032111.r43LBvZ3040508@svn.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201305032111.r43LBvZ3040508@svn.freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 May 2013 18:54:31 -0000 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