From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mxRN2-0009Zg-NH for kexec@lists.infradead.org; Wed, 15 Dec 2021 10:18:50 +0000 From: Sven Schnelle Subject: [PATCH v2 4/5] use slurp_proc_file() in get_command_line() Date: Wed, 15 Dec 2021 11:18:35 +0100 Message-Id: <20211215101836.1181165-5-svens@linux.ibm.com> In-Reply-To: <20211215101836.1181165-1-svens@linux.ibm.com> References: <20211215101836.1181165-1-svens@linux.ibm.com> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: Simon Horman Cc: kexec@lists.infradead.org, prudo@redhat.com, Sven Schnelle This way the size of the command line that get_command_line() can handle is no longer fixed. Signed-off-by: Sven Schnelle --- kexec/kexec.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/kexec/kexec.c b/kexec/kexec.c index a1acba2adf2a..e2c58de48565 100644 --- a/kexec/kexec.c +++ b/kexec/kexec.c @@ -1153,25 +1153,19 @@ static char *slurp_proc_file(const char *filename, size_t *len) */ char *get_command_line(void) { - FILE *fp; - char *line; - const int sizeof_line = 2048; - - line = malloc(sizeof_line); - if (line == NULL) - die("Could not allocate memory to read /proc/cmdline."); - - fp = fopen("/proc/cmdline", "r"); - if (!fp) - die("Could not open /proc/cmdline."); - - if (fgets(line, sizeof_line, fp) == NULL) - die("Can't read /proc/cmdline."); + char *p, *line; + size_t size; - fclose(fp); + line = slurp_proc_file("/proc/cmdline", &size); + if (!line || !size) + die("Failed to read /proc/cmdline\n"); /* strip newline */ - line[strlen(line) - 1] = '\0'; + line[size-1] = '\0'; + + p = strpbrk(line, "\r\n"); + if (p) + *p = '\0'; remove_parameter(line, "BOOT_IMAGE"); if (kexec_flags & KEXEC_ON_CRASH) -- 2.32.0 _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec