Bug#254475: The bug is still there in 0.97-21
Friedemann Baitinger
baiti at web.de
Sun Jan 28 18:50:57 CET 2007
have spent some time debugging the problem. I believe I have found two bugs:
The file /boot/grub/default was opened in read-only mode:
fopen(file, "r");
Later we're trying to write to it. In addition, the function
"read(&line, -1)" doesn't seem to do what it is supposed to do. "line"
always has garbage afterwards", needless to say that the two values we
later want to sscanf() out if it never get a value assigned so they stay
at the static initialized values of "-1". I don't know where
"read(&line, -1)" really reads from and where its prototype is declared
nor what library implements it but it definitely doesn't do what it is
supposed to do.
Here is a patch that I have verified that it really works:
--- builtins.c.orig 2007-01-28 16:46:18.000000000 +0100
+++ builtins.c 2007-01-28 18:33:17.000000000 +0100
@@ -3574,16 +3574,16 @@
default_file[i] = 0;
grub_strncat (default_file + i, "default", DEFAULT_FILE_BUFLEN - i);
- if(!(fp = fopen(default_file,"w")))
+ if(!(fp = fopen(default_file,"r+")))
{
errnum = ERR_READ;
goto fail;
}
- read(&line, -1);
-
+ fgets(line, bytes, fp);
+
sscanf(line, "%d:%d", &curr_prev_default, &curr_default);
-
+
if(curr_default != -1)
new_prev_default = curr_default;
else
@@ -3599,6 +3599,7 @@
else
sprintf(buf, "%d\n", new_default);
+ rewind(fp);
fprintf(fp, buf);
fail:
--
Friedemann Baitinger baiti at web.de
More information about the Pkg-grub-devel
mailing list