All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kexec.c: workaround getline and fscanf to make it *libc agnostic. Tested against klibc and dietlibc.
@ 2009-11-21 23:12 Andrea Adami
  2009-11-22  5:03 ` Simon Horman
  0 siblings, 1 reply; 12+ messages in thread
From: Andrea Adami @ 2009-11-21 23:12 UTC (permalink / raw)
  To: kexec; +Cc: Yuri Bushmelev, Andrea Adami


Signed-off-by: Andrea Adami <andrea.adami@gmail.com>
Signed-off-by: Yuri Bushmelev <jay4mail@gmail.com>
---
 kexec/kexec.c |   38 ++++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/kexec/kexec.c b/kexec/kexec.c
index ce105cd..a3ca79c 100644
--- a/kexec/kexec.c
+++ b/kexec/kexec.c
@@ -933,15 +933,32 @@ void usage(void)
 
 static int kexec_loaded(void)
 {
-	int ret;
+	long ret = -1;
 	FILE *fp;
+	char *p;
+	char line[3];
 
 	fp = fopen("/sys/kernel/kexec_loaded", "r");
 	if (fp == NULL)
 		return -1;
-	fscanf(fp, "%d", &ret);
+/*	fscanf(fp, "%d", &ret); */
+	p = fgets(line, sizeof(line), fp);
 	fclose(fp);
-	return ret;
+
+	if ( NULL == p)
+		return -1;
+
+	ret = strtol(line, &p, 10);
+
+	if (ret > INT_MAX)
+	/* Too long */
+		return -1;
+
+	if (p == line)
+	/* No digits were found */
+		return -1;
+
+	return (int)ret;
 }
 
 /*
@@ -989,18 +1006,23 @@ static void remove_parameter(char *line, const char *param_name)
 char *get_command_line(void)
 {
 	FILE *fp;
-	size_t len;
-	char *line = NULL;
+	const int sizeof_line = 1024;
+	char *line = malloc(sizeof_line); /* according to strdup() later */
 
 	fp = fopen("/proc/cmdline", "r");
 	if (!fp)
-		die("Could not read /proc/cmdline.");
-	getline(&line, &len, fp);
+		die("Could not open /proc/cmdline.");
+
+	if ( NULL == fgets(line, sizeof(line), fp) ) {
+		die("Can't read /proc/cmdline.");
+
+/* 	getline(&line, &len, fp); */
 	fclose(fp);
+	}
 
 	if (line) {
 		/* strip newline */
-		*(line + strlen(line) - 1) = 0;
+		line[strlen(line) - 1] = '\0';
 
 		remove_parameter(line, "BOOT_IMAGE");
 		if (kexec_flags & KEXEC_ON_CRASH)
-- 
1.6.4.4


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-11-27 10:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-21 23:12 [PATCH] kexec.c: workaround getline and fscanf to make it *libc agnostic. Tested against klibc and dietlibc Andrea Adami
2009-11-22  5:03 ` Simon Horman
2009-11-22  9:24   ` Bernhard Walle
2009-11-25 23:17     ` Simon Horman
2009-11-25 23:37       ` Bernhard Walle
2009-11-26  0:14         ` Simon Horman
2009-11-26 10:34           ` Yuri Bushmelev
2009-11-26 19:28             ` Bernhard Walle
2009-11-26 21:42               ` Simon Horman
2009-11-27  7:05                 ` Bernhard Walle
2009-11-27  9:26                 ` Yuri Bushmelev
2009-11-27 10:48                   ` Simon Horman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.