Hi Robert, At 22.29 03/02/2003, Robert Collins wrote:
I have just found the reason of this:On Tue, 2003-02-04 at 05:00, Guido Serassio wrote:> - File open is forced in binary mode This is a wrong way to tackle (whatever) problem you've encounteded. The caller of this function specifies the mode as binary or text. I'm applying the rest of the patches though.
On Windows, when opening a file as O_TEXT, the resulting bytes count from a read() can be different from the real disk size.
So errorTryLoadText() in errorpage.cc and netdbReloadState() in net_db.c doesn't work correctly.
So, attached there is a patch to fix this.
Only a question, O_TEXT is really needed ?, or we can simply change O_TEXT to O_BINARY for all platforms ?
Another thing:
I have discovered a bug in errorTryLoadText() when the read() fails: a NULL pointer is used in string functions. In the attached patch there is a fix to this too.
The problem is present in 2.5 too.
Regards
Guido
Cheers, Rob -- GPG key available at: <http://users.bigpond.net.au/robertc/keys.txt>.
- ======================================================= Serassio Guido Via Albenga, 11/4 10134 - Torino - ITALY E-mail: [EMAIL PROTECTED] WWW: http://www.serassio.it
Index: net_db.cc
===================================================================
RCS file: /cvsroot/squid/squid3/src/net_db.cc,v
retrieving revision 1.6
diff -u -p -r1.6 net_db.cc
--- net_db.cc 23 Jan 2003 03:14:42 -0000 1.6
+++ net_db.cc 4 Feb 2003 11:26:26 -0000
@@ -457,7 +457,11 @@ netdbReloadState(void)
* Solaris bugs, its a bad idea. fopen can fail if more than
* 256 FDs are open.
*/
+#ifdef _SQUID_MSWIN_
+ fd = file_open(path, O_RDONLY | O_BINARY);
+#else
fd = file_open(path, O_RDONLY | O_TEXT);
+#endif
if (fd < 0)
return;
if (fstat(fd, &sb) < 0) {
Index: errorpage.cc
===================================================================
RCS file: /cvsroot/squid/squid3/src/errorpage.cc,v
retrieving revision 1.9
diff -u -p -r1.9 errorpage.cc
--- errorpage.cc 28 Jan 2003 03:13:08 -0000 1.9
+++ errorpage.cc 4 Feb 2003 11:26:27 -0000
@@ -194,7 +194,11 @@ errorTryLoadText(const char *page_name,
char *text;
snprintf(path, sizeof(path), "%s/%s", dir, page_name);
+#ifdef _SQUID_MSWIN_
+ fd = file_open(path, O_RDONLY | O_BINARY);
+#else
fd = file_open(path, O_RDONLY | O_TEXT);
+#endif
if (fd < 0 || fstat(fd, &sb) < 0) {
debug(4, 0) ("errorTryLoadText: '%s': %s\n", path, xstrerror());
if (fd >= 0)
@@ -209,8 +213,10 @@ errorTryLoadText(const char *page_name,
text = NULL;
}
file_close(fd);
- if (strstr(text, "%s") == NULL)
- strcat(text, "%S"); /* add signature */
+ if (text != NULL) {
+ if (strstr(text, "%s") == NULL)
+ strcat(text, "%S"); /* add signature */
+ }
return text;
}
