From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id CA5BA15838C for ; Thu, 25 Jan 2024 02:54:00 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5ADECE29CC; Thu, 25 Jan 2024 02:53:59 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 4379AE29CC for ; Thu, 25 Jan 2024 02:53:59 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 710CB3433DB for ; Thu, 25 Jan 2024 02:53:58 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 9D835105D for ; Thu, 25 Jan 2024 02:53:56 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1706149539.76055a7dd0ab434e00df33b3577542bb69172aa8.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: pspax.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 76055a7dd0ab434e00df33b3577542bb69172aa8 X-VCS-Branch: master Date: Thu, 25 Jan 2024 02:53:56 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 94b64efc-ba7b-401c-b05b-a59df8e6c236 X-Archives-Hash: 002d521b3bce00d4dfd29be77379bca4 commit: 76055a7dd0ab434e00df33b3577542bb69172aa8 Author: Mike Frysinger gentoo org> AuthorDate: Thu Jan 25 02:25:39 2024 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Thu Jan 25 02:25:39 2024 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=76055a7d pspax: switch from fgets to getline This avoids limiting buffers to BUFSIZ which is a stdio.h define for stdio buffers, not for random files, and is not a guaranteed size. Signed-off-by: Mike Frysinger gentoo.org> pspax.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/pspax.c b/pspax.c index 04cae79..1cfd72f 100644 --- a/pspax.c +++ b/pspax.c @@ -119,12 +119,13 @@ static const char *get_proc_name(int pfd) static int get_proc_maps(int pfd) { FILE *fp; - static char str[BUFSIZ]; + static char *str = NULL; + static size_t len = 0; if ((fp = fopenat_r(pfd, "maps")) == NULL) return -1; - while (fgets(str, sizeof(str), fp)) { + while (getline(&str, &len, fp) != -1) { char *p; if ((p = strchr(str, ' ')) != NULL) { if (strlen(p) < 6) @@ -155,12 +156,13 @@ static int get_proc_maps(int pfd) static int print_executable_mappings(int pfd) { FILE *fp; - static char str[BUFSIZ]; + static char *str = NULL; + static size_t len = 0; if ((fp = fopenat_r(pfd, "maps")) == NULL) return -1; - while (fgets(str, sizeof(str), fp)) { + while (getline(&str, &len, fp) != -1) { char *p; if ((p = strchr(str, ' ')) != NULL) { if (strlen(p) < 6) @@ -200,20 +202,21 @@ static const struct passwd *get_proc_passwd(int pfd) static const char *get_proc_status(int pfd, const char *name) { FILE *fp; - size_t len; - static char str[BUFSIZ]; + size_t name_len; + static char *str = NULL; + static size_t len = 0; if ((fp = fopenat_r(pfd, "status")) == NULL) return NULL; - len = strlen(name); - while (fgets(str, sizeof(str), fp)) { - if (strncasecmp(str, name, len) != 0) + name_len = strlen(name); + while (getline(&str, &len, fp) != -1) { + if (strncasecmp(str, name, name_len) != 0) continue; - if (str[len] == ':') { + if (str[name_len] == ':') { fclose(fp); str[strlen(str) - 1] = 0; - return (str + len + 2); + return (str + name_len + 2); } } fclose(fp); @@ -225,12 +228,13 @@ static const char *get_pid_attr(int pfd) { FILE *fp; char *p; - static char buf[BUFSIZ]; + static char *buf = NULL; + static size_t len = 0; if ((fp = fopenat_r(pfd, "attr/current")) == NULL) return NULL; - if (fgets(buf, sizeof(buf), fp) == NULL) { + if (getline(&buf, &len, fp) == -1) { fclose(fp); return NULL; } @@ -247,12 +251,13 @@ static const char *get_pid_addr(int pfd) { FILE *fp; char *p; - static char buf[BUFSIZ]; + static char *buf = NULL; + static size_t len = 0; if ((fp = fopenat_r(pfd, "ipaddr")) == NULL) return NULL; - if (fgets(buf, sizeof(buf), fp) == NULL) { + if (getline(&buf, &len, fp) == -1) { fclose(fp); return NULL; }