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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id BE6691382C5 for ; Fri, 16 Feb 2018 20:07:46 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 203A1E0AE7; Fri, 16 Feb 2018 20:07:46 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E0F69E0AE7 for ; Fri, 16 Feb 2018 20:07:45 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 14AD2335C38 for ; Fri, 16 Feb 2018 20:07:45 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 97204216 for ; Fri, 16 Feb 2018 20:07:43 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1518811480.8dbdabcc5e0df8ac36722a4ba7bfe30664cc9919.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/rc/start-stop-daemon.c X-VCS-Directories: src/rc/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: 8dbdabcc5e0df8ac36722a4ba7bfe30664cc9919 X-VCS-Branch: master Date: Fri, 16 Feb 2018 20:07:43 +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-Archives-Salt: 61241f2c-f72c-468b-ad1f-016168485299 X-Archives-Hash: 6f5ed98208d7c43b8da58b0ec21c1aa0 commit: 8dbdabcc5e0df8ac36722a4ba7bfe30664cc9919 Author: William Hubbs gmail com> AuthorDate: Fri Feb 16 20:04:40 2018 +0000 Commit: William Hubbs gentoo org> CommitDate: Fri Feb 16 20:04:40 2018 +0000 URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8dbdabcc start-stop-daemon: clean up string handling src/rc/start-stop-daemon.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c index 54b89b2a..88b1e091 100644 --- a/src/rc/start-stop-daemon.c +++ b/src/rc/start-stop-daemon.c @@ -254,6 +254,7 @@ int main(int argc, char **argv) #endif int opt; + size_t size = 0; bool start = false; bool stop = false; bool oknodo = false; @@ -287,10 +288,10 @@ int main(int argc, char **argv) char *tmp, *newpath, *np; char *p; char *token; - char exec_file[PATH_MAX]; + char *exec_file = NULL; struct passwd *pw; struct group *gr; - char line[130]; + char *line = NULL; FILE *fp; size_t len; mode_t numask = 022; @@ -577,26 +578,22 @@ int main(int argc, char **argv) if (*exec == '/' || *exec == '.') { /* Full or relative path */ if (ch_root) - snprintf(exec_file, sizeof(exec_file), - "%s/%s", ch_root, exec); + xasprintf(&exec_file, "%s/%s", ch_root, exec); else - snprintf(exec_file, sizeof(exec_file), - "%s", exec); + xasprintf(&exec_file, "%s", exec); } else { /* Something in $PATH */ p = tmp = xstrdup(getenv("PATH")); - *exec_file = '\0'; + exec_file = NULL; while ((token = strsep(&p, ":"))) { if (ch_root) - snprintf(exec_file, sizeof(exec_file), - "%s/%s/%s", - ch_root, token, exec); + xasprintf(&exec_file, "%s/%s/%s", ch_root, token, exec); else - snprintf(exec_file, sizeof(exec_file), - "%s/%s", token, exec); - if (exists(exec_file)) + xasprintf(&exec_file, "%s/%s", token, exec); + if (exec_file && exists(exec_file)) break; - *exec_file = '\0'; + free(exec_file); + exec_file = NULL; } free(tmp); } @@ -604,6 +601,7 @@ int main(int argc, char **argv) if (start && !exists(exec_file)) { eerror("%s: %s does not exist", applet, *exec_file ? exec_file : exec); + free(exec_file); exit(EXIT_FAILURE); } @@ -617,7 +615,9 @@ int main(int argc, char **argv) if (interpreted && !pidfile) { fp = fopen(exec_file, "r"); if (fp) { - p = fgets(line, sizeof(line), fp); + line = NULL; + getline(&line, &size, fp); + p = line; fclose(fp); if (p != NULL && line[0] == '#' && line[1] == '!') { p = line + 2; @@ -629,7 +629,8 @@ int main(int argc, char **argv) if (p[len] == '\n') p[len] = '\0'; token = strsep(&p, " "); - strncpy(exec_file, token, sizeof(exec_file)); + free(exec_file); + xasprintf(&exec_file, "%s", token); opt = 0; for (nav = argv; *nav; nav++) opt++;