linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [another-patch] Real bugfix for raidtools
@ 2003-03-10 11:26 rgp
  0 siblings, 0 replies; only message in thread
From: rgp @ 2003-03-10 11:26 UTC (permalink / raw)
  To: linux-raid

[-- Attachment #1: Type: text/plain, Size: 705 bytes --]

Hey, y'all, here's another small patch for the latest raidtools (that I
know of).  It removes a problem in lsraid:  if a line from
/proc/partitions was >100 characters, it would be partially read, and
it's back end could cause segfaults or other nasties on the next
iteration.

The copyright on this patch is hereby abandoned.

It expects to be applied without my other patch, and visa versa, so some
munging may be in order.  The solution is not optimal anyway, but it was
quick.  If I get a line from fgets that does not have a newline, I
print a warning, discard it, and discard everything else until I DO get
a newline;

I also enlarged the buffer, but the best built buffers of mice and men
etc...



[-- Attachment #2: patch2 --]
[-- Type: text/plain, Size: 954 bytes --]

diff -r -u --minimal -w --new-file ../raidtools-1.00.3.orig/lsraid.c ./lsraid.c
--- ../raidtools-1.00.3.orig/lsraid.c	2003-01-15 03:58:25.000000000 -0500
+++ ./lsraid.c	2003-03-10 06:12:50.000000000 -0500
@@ -1029,6 +1029,10 @@
 
 static int load_partitions(LSRContext *ctxt)
 {
+//FIXME: use some factor of PATH_MAX or something.
+#undef MAX_LINE_LENGTH
+//#define MAX_LINE_LENGTH 20
+#define MAX_LINE_LENGTH 4096
     FILE *proc;
     int major, minor, rc;
     char line[MAX_LINE_LENGTH], name[MAX_LINE_LENGTH];
@@ -1047,6 +1051,16 @@
         rc = 0;
         if ((fgets(line, MAX_LINE_LENGTH, proc)) == NULL)
             break;
+		if (line[strlen(line)-1] != '\n') {
+			fprintf(stderr, "skipping long line: %s", line);
+			do {
+				if ((fgets(line, MAX_LINE_LENGTH, proc)) == NULL)
+					break;
+				fprintf(stderr,"%s", line);
+			} while (line[strlen(line)-1] != '\n');
+			continue;
+		};
+
 
         name[0] = 0;
         major = minor = 0;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-03-10 11:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-10 11:26 [another-patch] Real bugfix for raidtools rgp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).