From owner-svn-src-stable-11@freebsd.org Thu May 4 15:00:11 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 342C9D5E187; Thu, 4 May 2017 15:00:11 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EAB481BD0; Thu, 4 May 2017 15:00:10 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v44F09mV011947; Thu, 4 May 2017 15:00:09 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v44F09rC011945; Thu, 4 May 2017 15:00:09 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201705041500.v44F09rC011945@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Thu, 4 May 2017 15:00:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r317797 - stable/11/lib/libthread_db X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 May 2017 15:00:11 -0000 Author: pfg Date: Thu May 4 15:00:09 2017 New Revision: 317797 URL: https://svnweb.freebsd.org/changeset/base/317797 Log: MFC r317200, r317201, r317216: libthread_db: unsign map_len and use reallocarray(3). Lengths are not negative, so map_len should be unsigned. Unsign the corresponding indexes too and bring a small use of reallocarray(3). Reorder the memset to be consistent with the reallocarray. Modified: stable/11/lib/libthread_db/libpthread_db.c stable/11/lib/libthread_db/libpthread_db.h Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libthread_db/libpthread_db.c ============================================================================== --- stable/11/lib/libthread_db/libpthread_db.c Thu May 4 14:55:07 2017 (r317796) +++ stable/11/lib/libthread_db/libpthread_db.c Thu May 4 15:00:09 2017 (r317797) @@ -74,7 +74,8 @@ pt_map_thread(const td_thragent_t *const { td_thragent_t *ta = __DECONST(td_thragent_t *, const_ta); struct pt_map *new; - int i, first = -1; + int first = -1; + unsigned int i; /* leave zero out */ for (i = 1; i < ta->map_len; ++i) { @@ -94,12 +95,12 @@ pt_map_thread(const td_thragent_t *const ta->map_len = 20; first = 1; } else { - new = realloc(ta->map, - sizeof(struct pt_map) * ta->map_len * 2); + new = reallocarray(ta->map, ta->map_len, + 2 * sizeof(struct pt_map)); if (new == NULL) return (-1); - memset(new + ta->map_len, '\0', sizeof(struct pt_map) * - ta->map_len); + memset(new + ta->map_len, '\0', ta->map_len * + sizeof(struct pt_map)); first = ta->map_len; ta->map = new; ta->map_len *= 2; @@ -226,7 +227,7 @@ pt_ta_map_id2thr(const td_thragent_t *ta TDBG_FUNC(); - if (id < 0 || id >= ta->map_len || ta->map[id].type == PT_NONE) + if (id < 0 || id >= (long)ta->map_len || ta->map[id].type == PT_NONE) return (TD_NOTHR); ret = thr_pread_ptr(ta, ta->thread_list_addr, &pt); @@ -1047,7 +1048,7 @@ pt_thr_sstep(const td_thrhandle_t *th, i static void pt_unmap_lwp(const td_thragent_t *ta, lwpid_t lwp) { - int i; + unsigned int i; for (i = 0; i < ta->map_len; ++i) { if (ta->map[i].type == PT_LWP && ta->map[i].lwp == lwp) { @@ -1061,7 +1062,7 @@ static int pt_validate(const td_thrhandle_t *th) { - if (th->th_tid < 0 || th->th_tid >= th->th_ta->map_len || + if (th->th_tid < 0 || th->th_tid >= (long)th->th_ta->map_len || th->th_ta->map[th->th_tid].type == PT_NONE) return (TD_NOTHR); return (TD_OK); Modified: stable/11/lib/libthread_db/libpthread_db.h ============================================================================== --- stable/11/lib/libthread_db/libpthread_db.h Thu May 4 14:55:07 2017 (r317796) +++ stable/11/lib/libthread_db/libpthread_db.h Thu May 4 15:00:09 2017 (r317797) @@ -77,7 +77,7 @@ struct td_thragent { int thread_off_sigmask; int thread_off_sigpend; struct pt_map *map; - int map_len; + unsigned int map_len; }; void pt_md_init(void);