Fossil SCM

Ensure that ALL fopen() calls include 'b' in their modes. The git import/export fopen()s did not have this, which may (hypothetically, but unproven) lead to EOL conversion on Windows.

stephan 2025-04-08 12:49 trunk
Commit 13049ef2458aa5795b9c9369bec46a28de645f4e0371eb293c9e95953dba65a2
--- src/backoffice.c
+++ src/backoffice.c
@@ -628,11 +628,11 @@
628628
int nTotal = 0;
629629
#if !defined(_WIN32)
630630
struct timeval sStart, sEnd;
631631
#endif
632632
if( zLog==0 ) zLog = db_get("backoffice-logfile",0);
633
- if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){
633
+ if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"ab"))!=0 ){
634634
int i;
635635
char *zName = db_get("project-name",0);
636636
#if !defined(_WIN32)
637637
gettimeofday(&sStart, 0);
638638
signal(SIGSEGV, backoffice_signal_handler);
639639
--- src/backoffice.c
+++ src/backoffice.c
@@ -628,11 +628,11 @@
628 int nTotal = 0;
629 #if !defined(_WIN32)
630 struct timeval sStart, sEnd;
631 #endif
632 if( zLog==0 ) zLog = db_get("backoffice-logfile",0);
633 if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"a"))!=0 ){
634 int i;
635 char *zName = db_get("project-name",0);
636 #if !defined(_WIN32)
637 gettimeofday(&sStart, 0);
638 signal(SIGSEGV, backoffice_signal_handler);
639
--- src/backoffice.c
+++ src/backoffice.c
@@ -628,11 +628,11 @@
628 int nTotal = 0;
629 #if !defined(_WIN32)
630 struct timeval sStart, sEnd;
631 #endif
632 if( zLog==0 ) zLog = db_get("backoffice-logfile",0);
633 if( zLog && zLog[0] && (backofficeFILE = fossil_fopen(zLog,"ab"))!=0 ){
634 int i;
635 char *zName = db_get("project-name",0);
636 #if !defined(_WIN32)
637 gettimeofday(&sStart, 0);
638 signal(SIGSEGV, backoffice_signal_handler);
639
+2 -2
--- src/export.c
+++ src/export.c
@@ -517,11 +517,11 @@
517517
if( markfile_in!=0 ){
518518
Stmt qb,qc;
519519
FILE *f;
520520
int rid;
521521
522
- f = fossil_fopen(markfile_in, "r");
522
+ f = fossil_fopen(markfile_in, "rb");
523523
if( f==0 ){
524524
fossil_fatal("cannot open %s for reading", markfile_in);
525525
}
526526
if( import_marks(f, &blobs, &vers, &unused_mark)<0 ){
527527
fossil_fatal("error importing marks from file: %s", markfile_in);
@@ -733,11 +733,11 @@
733733
}
734734
db_finalize(&q);
735735
736736
if( markfile_out!=0 ){
737737
FILE *f;
738
- f = fossil_fopen(markfile_out, "w");
738
+ f = fossil_fopen(markfile_out, "wb");
739739
if( f == 0 ){
740740
fossil_fatal("cannot open %s for writing", markfile_out);
741741
}
742742
export_marks(f, &blobs, &vers);
743743
if( ferror(f)!=0 || fclose(f)!=0 ){
744744
--- src/export.c
+++ src/export.c
@@ -517,11 +517,11 @@
517 if( markfile_in!=0 ){
518 Stmt qb,qc;
519 FILE *f;
520 int rid;
521
522 f = fossil_fopen(markfile_in, "r");
523 if( f==0 ){
524 fossil_fatal("cannot open %s for reading", markfile_in);
525 }
526 if( import_marks(f, &blobs, &vers, &unused_mark)<0 ){
527 fossil_fatal("error importing marks from file: %s", markfile_in);
@@ -733,11 +733,11 @@
733 }
734 db_finalize(&q);
735
736 if( markfile_out!=0 ){
737 FILE *f;
738 f = fossil_fopen(markfile_out, "w");
739 if( f == 0 ){
740 fossil_fatal("cannot open %s for writing", markfile_out);
741 }
742 export_marks(f, &blobs, &vers);
743 if( ferror(f)!=0 || fclose(f)!=0 ){
744
--- src/export.c
+++ src/export.c
@@ -517,11 +517,11 @@
517 if( markfile_in!=0 ){
518 Stmt qb,qc;
519 FILE *f;
520 int rid;
521
522 f = fossil_fopen(markfile_in, "rb");
523 if( f==0 ){
524 fossil_fatal("cannot open %s for reading", markfile_in);
525 }
526 if( import_marks(f, &blobs, &vers, &unused_mark)<0 ){
527 fossil_fatal("error importing marks from file: %s", markfile_in);
@@ -733,11 +733,11 @@
733 }
734 db_finalize(&q);
735
736 if( markfile_out!=0 ){
737 FILE *f;
738 f = fossil_fopen(markfile_out, "wb");
739 if( f == 0 ){
740 fossil_fatal("cannot open %s for writing", markfile_out);
741 }
742 export_marks(f, &blobs, &vers);
743 if( ferror(f)!=0 || fclose(f)!=0 ){
744
+2 -2
--- src/import.c
+++ src/import.c
@@ -1930,11 +1930,11 @@
19301930
"CREATE TEMP TABLE xbranch(tname TEXT UNIQUE, brnm TEXT);"
19311931
"CREATE TEMP TABLE xtag(tname TEXT UNIQUE, tcontent TEXT);"
19321932
);
19331933
19341934
if( markfile_in ){
1935
- FILE *f = fossil_fopen(markfile_in, "r");
1935
+ FILE *f = fossil_fopen(markfile_in, "rb");
19361936
if( !f ){
19371937
fossil_fatal("cannot open %s for reading", markfile_in);
19381938
}
19391939
if( import_marks(f, &blobs, NULL, NULL)<0 ){
19401940
fossil_fatal("error importing marks from file: %s", markfile_in);
@@ -1988,11 +1988,11 @@
19881988
}else{
19891989
bag_insert(&vers, rid);
19901990
}
19911991
}
19921992
db_finalize(&q_marks);
1993
- f = fossil_fopen(markfile_out, "w");
1993
+ f = fossil_fopen(markfile_out, "wb");
19941994
if( !f ){
19951995
fossil_fatal("cannot open %s for writing", markfile_out);
19961996
}
19971997
export_marks(f, &blobs, &vers);
19981998
fclose(f);
19991999
--- src/import.c
+++ src/import.c
@@ -1930,11 +1930,11 @@
1930 "CREATE TEMP TABLE xbranch(tname TEXT UNIQUE, brnm TEXT);"
1931 "CREATE TEMP TABLE xtag(tname TEXT UNIQUE, tcontent TEXT);"
1932 );
1933
1934 if( markfile_in ){
1935 FILE *f = fossil_fopen(markfile_in, "r");
1936 if( !f ){
1937 fossil_fatal("cannot open %s for reading", markfile_in);
1938 }
1939 if( import_marks(f, &blobs, NULL, NULL)<0 ){
1940 fossil_fatal("error importing marks from file: %s", markfile_in);
@@ -1988,11 +1988,11 @@
1988 }else{
1989 bag_insert(&vers, rid);
1990 }
1991 }
1992 db_finalize(&q_marks);
1993 f = fossil_fopen(markfile_out, "w");
1994 if( !f ){
1995 fossil_fatal("cannot open %s for writing", markfile_out);
1996 }
1997 export_marks(f, &blobs, &vers);
1998 fclose(f);
1999
--- src/import.c
+++ src/import.c
@@ -1930,11 +1930,11 @@
1930 "CREATE TEMP TABLE xbranch(tname TEXT UNIQUE, brnm TEXT);"
1931 "CREATE TEMP TABLE xtag(tname TEXT UNIQUE, tcontent TEXT);"
1932 );
1933
1934 if( markfile_in ){
1935 FILE *f = fossil_fopen(markfile_in, "rb");
1936 if( !f ){
1937 fossil_fatal("cannot open %s for reading", markfile_in);
1938 }
1939 if( import_marks(f, &blobs, NULL, NULL)<0 ){
1940 fossil_fatal("error importing marks from file: %s", markfile_in);
@@ -1988,11 +1988,11 @@
1988 }else{
1989 bag_insert(&vers, rid);
1990 }
1991 }
1992 db_finalize(&q_marks);
1993 f = fossil_fopen(markfile_out, "wb");
1994 if( !f ){
1995 fossil_fatal("cannot open %s for writing", markfile_out);
1996 }
1997 export_marks(f, &blobs, &vers);
1998 fclose(f);
1999
+1 -1
--- src/printf.c
+++ src/printf.c
@@ -1086,11 +1086,11 @@
10861086
"REQUEST_URI", "SCRIPT_NAME" };
10871087
if( g.zErrlog==0 ) return;
10881088
if( g.zErrlog[0]=='-' && g.zErrlog[1]==0 ){
10891089
out = stderr;
10901090
}else{
1091
- out = fossil_fopen(g.zErrlog, "a");
1091
+ out = fossil_fopen(g.zErrlog, "ab");
10921092
if( out==0 ) return;
10931093
}
10941094
now = time(0);
10951095
pNow = gmtime(&now);
10961096
fprintf(out, "------------- %04d-%02d-%02d %02d:%02d:%02d UTC ------------\n",
10971097
--- src/printf.c
+++ src/printf.c
@@ -1086,11 +1086,11 @@
1086 "REQUEST_URI", "SCRIPT_NAME" };
1087 if( g.zErrlog==0 ) return;
1088 if( g.zErrlog[0]=='-' && g.zErrlog[1]==0 ){
1089 out = stderr;
1090 }else{
1091 out = fossil_fopen(g.zErrlog, "a");
1092 if( out==0 ) return;
1093 }
1094 now = time(0);
1095 pNow = gmtime(&now);
1096 fprintf(out, "------------- %04d-%02d-%02d %02d:%02d:%02d UTC ------------\n",
1097
--- src/printf.c
+++ src/printf.c
@@ -1086,11 +1086,11 @@
1086 "REQUEST_URI", "SCRIPT_NAME" };
1087 if( g.zErrlog==0 ) return;
1088 if( g.zErrlog[0]=='-' && g.zErrlog[1]==0 ){
1089 out = stderr;
1090 }else{
1091 out = fossil_fopen(g.zErrlog, "ab");
1092 if( out==0 ) return;
1093 }
1094 now = time(0);
1095 pNow = gmtime(&now);
1096 fprintf(out, "------------- %04d-%02d-%02d %02d:%02d:%02d UTC ------------\n",
1097
--- src/security_audit.c
+++ src/security_audit.c
@@ -608,11 +608,11 @@
608608
}else{
609609
@ add the "--errorlog <i>FILENAME</i>" option to the
610610
@ "%h(g.argv[0]) %h(g.zCmdName)" command that launched this server.
611611
}
612612
}else{
613
- FILE *pTest = fossil_fopen(g.zErrlog,"a");
613
+ FILE *pTest = fossil_fopen(g.zErrlog,"ab");
614614
if( pTest==0 ){
615615
@ <li><p>
616616
@ <b>Error:</b>
617617
@ There is an error log at "%h(g.zErrlog)" but that file is not
618618
@ writable and so no logging will occur.
@@ -862,11 +862,11 @@
862862
no_error_log_available();
863863
style_finish_page();
864864
return;
865865
}
866866
if( P("truncate1") && cgi_csrf_safe(2) ){
867
- fclose(fopen(g.zErrlog,"w"));
867
+ fclose(fopen(g.zErrlog,"wb"));
868868
}
869869
if( P("download") ){
870870
Blob log;
871871
blob_read_from_file(&log, g.zErrlog, ExtFILE);
872872
cgi_set_content_type("text/plain");
873873
--- src/security_audit.c
+++ src/security_audit.c
@@ -608,11 +608,11 @@
608 }else{
609 @ add the "--errorlog <i>FILENAME</i>" option to the
610 @ "%h(g.argv[0]) %h(g.zCmdName)" command that launched this server.
611 }
612 }else{
613 FILE *pTest = fossil_fopen(g.zErrlog,"a");
614 if( pTest==0 ){
615 @ <li><p>
616 @ <b>Error:</b>
617 @ There is an error log at "%h(g.zErrlog)" but that file is not
618 @ writable and so no logging will occur.
@@ -862,11 +862,11 @@
862 no_error_log_available();
863 style_finish_page();
864 return;
865 }
866 if( P("truncate1") && cgi_csrf_safe(2) ){
867 fclose(fopen(g.zErrlog,"w"));
868 }
869 if( P("download") ){
870 Blob log;
871 blob_read_from_file(&log, g.zErrlog, ExtFILE);
872 cgi_set_content_type("text/plain");
873
--- src/security_audit.c
+++ src/security_audit.c
@@ -608,11 +608,11 @@
608 }else{
609 @ add the "--errorlog <i>FILENAME</i>" option to the
610 @ "%h(g.argv[0]) %h(g.zCmdName)" command that launched this server.
611 }
612 }else{
613 FILE *pTest = fossil_fopen(g.zErrlog,"ab");
614 if( pTest==0 ){
615 @ <li><p>
616 @ <b>Error:</b>
617 @ There is an error log at "%h(g.zErrlog)" but that file is not
618 @ writable and so no logging will occur.
@@ -862,11 +862,11 @@
862 no_error_log_available();
863 style_finish_page();
864 return;
865 }
866 if( P("truncate1") && cgi_csrf_safe(2) ){
867 fclose(fopen(g.zErrlog,"wb"));
868 }
869 if( P("download") ){
870 Blob log;
871 blob_read_from_file(&log, g.zErrlog, ExtFILE);
872 cgi_set_content_type("text/plain");
873

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button