Fossil SCM

Fixed a double-free caused by refactoring. Was being triggered in web mode but not CLI mode, strangely enough, though the code was hit by both. Other minor cleanups and fixes.

stephan 2020-05-02 21:57 UTC checkin-without-checkout
Commit 6f749dfbc8ec5d3c80678a872687fd05cd246cccf36dc5646ba72b115fe1f099
1 file changed +19 -14
+19 -14
--- src/checkin.c
+++ src/checkin.c
@@ -2831,14 +2831,14 @@
28312831
blob_reset(&p->fileHash);
28322832
if(p->pParent){
28332833
manifest_destroy(p->pParent);
28342834
}
28352835
fossil_free(p->zFilename);
2836
- fossil_free(p->zMimetype);
2836
+ fossil_free(p->zDate);
28372837
fossil_free(p->zParentUuid);
2838
+ fossil_free(p->zMimetype);
28382839
fossil_free(p->zUser);
2839
- fossil_free(p->zDate);
28402840
CheckinMiniInfo_init(p);
28412841
}
28422842
28432843
/*
28442844
** Internal helper which returns an F-card perms string suitable for
@@ -3039,11 +3039,11 @@
30393039
if(blob_size(&pCI->comment)!=0){
30403040
blob_appendf(pOut, "C %F\n", blob_str(&pCI->comment));
30413041
}else{
30423042
blob_append(pOut, "C (no\\scomment)\n", 16);
30433043
}
3044
- blob_appendf(pOut, "D %z\n", pCI->zDate);
3044
+ blob_appendf(pOut, "D %s\n", pCI->zDate);
30453045
if(create_manifest_mini_fcards(pOut,pCI,asDelta,pErr)==0){
30463046
return 0;
30473047
}
30483048
if(pCI->zMimetype!=0 && pCI->zMimetype[0]!=0){
30493049
blob_appendf(pOut, "N %F\n", pCI->zMimetype);
@@ -3133,11 +3133,11 @@
31333133
}
31343134
fossil_free(zProjCode);
31353135
}
31363136
db_begin_transaction();
31373137
3138
- if(pCI->pParent==0 && pCI->zParentUuid){
3138
+ if(pCI->pParent==0 && pCI->zParentUuid==0){
31393139
ci_err((pErr, "Cannot determine parent version."));
31403140
}
31413141
else if(pCI->pParent==0){
31423142
pCI->pParent = manifest_get_by_name(pCI->zParentUuid, 0);
31433143
if(pCI->pParent==0){
@@ -3667,11 +3667,10 @@
36673667
const char * zRev = P("r"); /* checkin version */
36683668
const char * zContent = P("content"); /* file content */
36693669
const char * zComment = P("comment"); /* checkin comment */
36703670
CheckinMiniInfo cimi; /* Checkin state */
36713671
int submitMode = 0; /* See mapping below */
3672
- char * zRevResolved = 0; /* Resolved zRev */
36733672
int vid, newVid = 0; /* checkin rid */
36743673
char * zFileUuid = 0; /* File content UUID */
36753674
int frid = 0; /* File content rid */
36763675
Blob err = empty_blob; /* Error report */
36773676
const char * zFlagCheck = 0; /* Temp url flag holder */
@@ -3722,11 +3721,11 @@
37223721
if(0==vid){
37233722
fail((&err,"Could not resolve checkin version."));
37243723
}
37253724
37263725
/* Find the repo-side file entry or fail... */
3727
- zRevResolved = rid_to_uuid(vid);
3726
+ cimi.zParentUuid = rid_to_uuid(vid);
37283727
db_prepare(&stmt, "SELECT uuid, perm FROM files_of_checkin "
37293728
"WHERE filename=%Q %s AND checkinID=%d",
37303729
zFilename, filename_collation(), vid);
37313730
if(SQLITE_ROW==db_step(&stmt)){
37323731
const char * zPerm = db_column_text(&stmt, 1);
@@ -3737,11 +3736,12 @@
37373736
zFileUuid = mprintf("%s",db_column_text(&stmt, 0));
37383737
}
37393738
db_finalize(&stmt);
37403739
if(!zFileUuid){
37413740
fail((&err,"Checkin [%S] does not contain file: "
3742
- "<code>%h</code>", zRevResolved, zFilename));
3741
+ "<code>%h</code>",
3742
+ cimi.zParentUuid, zFilename));
37433743
}
37443744
frid = fast_uuid_to_rid(zFileUuid);
37453745
assert(frid);
37463746
37473747
/* Read file content from submit request or repo... */
@@ -3763,25 +3763,29 @@
37633763
37643764
fp("<h1>Editing:</h1>");
37653765
fp("<p class='fileedit-hint'>");
37663766
fp("File: <code>%h</code><br>"
37673767
"Version: <code id='r-label'>%s</code><br>",
3768
- zFilename, zRevResolved);
3768
+ zFilename, cimi.zParentUuid);
37693769
fp("Permalink: <code>"
37703770
"<a id='permalink' href='%R/fileedit?file=%T&r=%!S'>"
37713771
"/fileedit?file=%T&r=%!S</a></code><br>"
37723772
"(Clicking the permalink will reload the page and discard "
37733773
"all edits!)",
3774
- zFilename, zRevResolved, zFilename, zRevResolved);
3774
+ zFilename, cimi.zParentUuid,
3775
+ zFilename, cimi.zParentUuid);
37753776
fp("</p>");
3776
- fp("<p>This page is <em>far from complete</em>.</p>\n");
3777
+ fp("<p>This page is <em>far from complete</em> and may still have "
3778
+ "significant bugs. USE AT YOUR OWN RISK, preferably on a test "
3779
+ "repo.</p>\n");
37773780
37783781
fp("<form action='%R/fileedit' method='POST' "
37793782
"class='fileedit-form'>\n");
37803783
37813784
/******* Hidden fields *******/
3782
- fp("<input type='hidden' name='r' value='%s'>", zRevResolved);
3785
+ fp("<input type='hidden' name='r' value='%s'>",
3786
+ cimi.zParentUuid);
37833787
fp("<input type='hidden' name='file' value='%T'>",
37843788
zFilename);
37853789
37863790
/******* Comment *******/
37873791
fp("<h3>Checkin Comment</h3>\n");
@@ -3924,12 +3928,12 @@
39243928
if(zComment && *zComment){
39253929
blob_append(&cimi.comment, zComment, -1);
39263930
}else{
39273931
fail((&err,"Empty comment is not permitted."));
39283932
}
3929
- cimi.pParent = manifest_get(vid, CFTYPE_MANIFEST, 0);
3930
- assert(cimi.pParent && "We know vid is valid.");
3933
+ /*cimi.pParent = manifest_get(vid, CFTYPE_MANIFEST, 0);
3934
+ assert(cimi.pParent && "We know vid is valid.");*/
39313935
cimi.zFilename = mprintf("%s",zFilename);
39323936
cimi.pMfOut = &manifest;
39333937
checkin_mini(&cimi, &newVid, &err);
39343938
if(newVid!=0){
39353939
zNewUuid = rid_to_uuid(newVid);
@@ -3963,13 +3967,15 @@
39633967
"link.innerText=urlShort;\n"
39643968
"link.setAttribute('href',urlFull);\n",
39653969
zFilename, zNewUuid, zFilename, zNewUuid);
39663970
}
39673971
fossil_free(zNewUuid);
3972
+ zNewUuid = 0;
39683973
}
39693974
/* On error, the error message is in the err blob and will
39703975
** be emitted below. */
3976
+ cimi.pMfOut = 0;
39713977
blob_reset(&manifest);
39723978
}else if(2==submitMode/*preview*/){
39733979
/* TODO */
39743980
fail((&err,"Preview mode is still TODO."));
39753981
}else if(3==submitMode/*diff*/){
@@ -3979,11 +3985,10 @@
39793985
goto end_footer;
39803986
}
39813987
39823988
end_footer:
39833989
zContent = 0;
3984
- fossil_free(zRevResolved);
39853990
fossil_free(zFileUuid);
39863991
if(stmt.pStmt){
39873992
db_finalize(&stmt);
39883993
}
39893994
if(blob_size(&err)){
39903995
--- src/checkin.c
+++ src/checkin.c
@@ -2831,14 +2831,14 @@
2831 blob_reset(&p->fileHash);
2832 if(p->pParent){
2833 manifest_destroy(p->pParent);
2834 }
2835 fossil_free(p->zFilename);
2836 fossil_free(p->zMimetype);
2837 fossil_free(p->zParentUuid);
 
2838 fossil_free(p->zUser);
2839 fossil_free(p->zDate);
2840 CheckinMiniInfo_init(p);
2841 }
2842
2843 /*
2844 ** Internal helper which returns an F-card perms string suitable for
@@ -3039,11 +3039,11 @@
3039 if(blob_size(&pCI->comment)!=0){
3040 blob_appendf(pOut, "C %F\n", blob_str(&pCI->comment));
3041 }else{
3042 blob_append(pOut, "C (no\\scomment)\n", 16);
3043 }
3044 blob_appendf(pOut, "D %z\n", pCI->zDate);
3045 if(create_manifest_mini_fcards(pOut,pCI,asDelta,pErr)==0){
3046 return 0;
3047 }
3048 if(pCI->zMimetype!=0 && pCI->zMimetype[0]!=0){
3049 blob_appendf(pOut, "N %F\n", pCI->zMimetype);
@@ -3133,11 +3133,11 @@
3133 }
3134 fossil_free(zProjCode);
3135 }
3136 db_begin_transaction();
3137
3138 if(pCI->pParent==0 && pCI->zParentUuid){
3139 ci_err((pErr, "Cannot determine parent version."));
3140 }
3141 else if(pCI->pParent==0){
3142 pCI->pParent = manifest_get_by_name(pCI->zParentUuid, 0);
3143 if(pCI->pParent==0){
@@ -3667,11 +3667,10 @@
3667 const char * zRev = P("r"); /* checkin version */
3668 const char * zContent = P("content"); /* file content */
3669 const char * zComment = P("comment"); /* checkin comment */
3670 CheckinMiniInfo cimi; /* Checkin state */
3671 int submitMode = 0; /* See mapping below */
3672 char * zRevResolved = 0; /* Resolved zRev */
3673 int vid, newVid = 0; /* checkin rid */
3674 char * zFileUuid = 0; /* File content UUID */
3675 int frid = 0; /* File content rid */
3676 Blob err = empty_blob; /* Error report */
3677 const char * zFlagCheck = 0; /* Temp url flag holder */
@@ -3722,11 +3721,11 @@
3722 if(0==vid){
3723 fail((&err,"Could not resolve checkin version."));
3724 }
3725
3726 /* Find the repo-side file entry or fail... */
3727 zRevResolved = rid_to_uuid(vid);
3728 db_prepare(&stmt, "SELECT uuid, perm FROM files_of_checkin "
3729 "WHERE filename=%Q %s AND checkinID=%d",
3730 zFilename, filename_collation(), vid);
3731 if(SQLITE_ROW==db_step(&stmt)){
3732 const char * zPerm = db_column_text(&stmt, 1);
@@ -3737,11 +3736,12 @@
3737 zFileUuid = mprintf("%s",db_column_text(&stmt, 0));
3738 }
3739 db_finalize(&stmt);
3740 if(!zFileUuid){
3741 fail((&err,"Checkin [%S] does not contain file: "
3742 "<code>%h</code>", zRevResolved, zFilename));
 
3743 }
3744 frid = fast_uuid_to_rid(zFileUuid);
3745 assert(frid);
3746
3747 /* Read file content from submit request or repo... */
@@ -3763,25 +3763,29 @@
3763
3764 fp("<h1>Editing:</h1>");
3765 fp("<p class='fileedit-hint'>");
3766 fp("File: <code>%h</code><br>"
3767 "Version: <code id='r-label'>%s</code><br>",
3768 zFilename, zRevResolved);
3769 fp("Permalink: <code>"
3770 "<a id='permalink' href='%R/fileedit?file=%T&r=%!S'>"
3771 "/fileedit?file=%T&r=%!S</a></code><br>"
3772 "(Clicking the permalink will reload the page and discard "
3773 "all edits!)",
3774 zFilename, zRevResolved, zFilename, zRevResolved);
 
3775 fp("</p>");
3776 fp("<p>This page is <em>far from complete</em>.</p>\n");
 
 
3777
3778 fp("<form action='%R/fileedit' method='POST' "
3779 "class='fileedit-form'>\n");
3780
3781 /******* Hidden fields *******/
3782 fp("<input type='hidden' name='r' value='%s'>", zRevResolved);
 
3783 fp("<input type='hidden' name='file' value='%T'>",
3784 zFilename);
3785
3786 /******* Comment *******/
3787 fp("<h3>Checkin Comment</h3>\n");
@@ -3924,12 +3928,12 @@
3924 if(zComment && *zComment){
3925 blob_append(&cimi.comment, zComment, -1);
3926 }else{
3927 fail((&err,"Empty comment is not permitted."));
3928 }
3929 cimi.pParent = manifest_get(vid, CFTYPE_MANIFEST, 0);
3930 assert(cimi.pParent && "We know vid is valid.");
3931 cimi.zFilename = mprintf("%s",zFilename);
3932 cimi.pMfOut = &manifest;
3933 checkin_mini(&cimi, &newVid, &err);
3934 if(newVid!=0){
3935 zNewUuid = rid_to_uuid(newVid);
@@ -3963,13 +3967,15 @@
3963 "link.innerText=urlShort;\n"
3964 "link.setAttribute('href',urlFull);\n",
3965 zFilename, zNewUuid, zFilename, zNewUuid);
3966 }
3967 fossil_free(zNewUuid);
 
3968 }
3969 /* On error, the error message is in the err blob and will
3970 ** be emitted below. */
 
3971 blob_reset(&manifest);
3972 }else if(2==submitMode/*preview*/){
3973 /* TODO */
3974 fail((&err,"Preview mode is still TODO."));
3975 }else if(3==submitMode/*diff*/){
@@ -3979,11 +3985,10 @@
3979 goto end_footer;
3980 }
3981
3982 end_footer:
3983 zContent = 0;
3984 fossil_free(zRevResolved);
3985 fossil_free(zFileUuid);
3986 if(stmt.pStmt){
3987 db_finalize(&stmt);
3988 }
3989 if(blob_size(&err)){
3990
--- src/checkin.c
+++ src/checkin.c
@@ -2831,14 +2831,14 @@
2831 blob_reset(&p->fileHash);
2832 if(p->pParent){
2833 manifest_destroy(p->pParent);
2834 }
2835 fossil_free(p->zFilename);
2836 fossil_free(p->zDate);
2837 fossil_free(p->zParentUuid);
2838 fossil_free(p->zMimetype);
2839 fossil_free(p->zUser);
 
2840 CheckinMiniInfo_init(p);
2841 }
2842
2843 /*
2844 ** Internal helper which returns an F-card perms string suitable for
@@ -3039,11 +3039,11 @@
3039 if(blob_size(&pCI->comment)!=0){
3040 blob_appendf(pOut, "C %F\n", blob_str(&pCI->comment));
3041 }else{
3042 blob_append(pOut, "C (no\\scomment)\n", 16);
3043 }
3044 blob_appendf(pOut, "D %s\n", pCI->zDate);
3045 if(create_manifest_mini_fcards(pOut,pCI,asDelta,pErr)==0){
3046 return 0;
3047 }
3048 if(pCI->zMimetype!=0 && pCI->zMimetype[0]!=0){
3049 blob_appendf(pOut, "N %F\n", pCI->zMimetype);
@@ -3133,11 +3133,11 @@
3133 }
3134 fossil_free(zProjCode);
3135 }
3136 db_begin_transaction();
3137
3138 if(pCI->pParent==0 && pCI->zParentUuid==0){
3139 ci_err((pErr, "Cannot determine parent version."));
3140 }
3141 else if(pCI->pParent==0){
3142 pCI->pParent = manifest_get_by_name(pCI->zParentUuid, 0);
3143 if(pCI->pParent==0){
@@ -3667,11 +3667,10 @@
3667 const char * zRev = P("r"); /* checkin version */
3668 const char * zContent = P("content"); /* file content */
3669 const char * zComment = P("comment"); /* checkin comment */
3670 CheckinMiniInfo cimi; /* Checkin state */
3671 int submitMode = 0; /* See mapping below */
 
3672 int vid, newVid = 0; /* checkin rid */
3673 char * zFileUuid = 0; /* File content UUID */
3674 int frid = 0; /* File content rid */
3675 Blob err = empty_blob; /* Error report */
3676 const char * zFlagCheck = 0; /* Temp url flag holder */
@@ -3722,11 +3721,11 @@
3721 if(0==vid){
3722 fail((&err,"Could not resolve checkin version."));
3723 }
3724
3725 /* Find the repo-side file entry or fail... */
3726 cimi.zParentUuid = rid_to_uuid(vid);
3727 db_prepare(&stmt, "SELECT uuid, perm FROM files_of_checkin "
3728 "WHERE filename=%Q %s AND checkinID=%d",
3729 zFilename, filename_collation(), vid);
3730 if(SQLITE_ROW==db_step(&stmt)){
3731 const char * zPerm = db_column_text(&stmt, 1);
@@ -3737,11 +3736,12 @@
3736 zFileUuid = mprintf("%s",db_column_text(&stmt, 0));
3737 }
3738 db_finalize(&stmt);
3739 if(!zFileUuid){
3740 fail((&err,"Checkin [%S] does not contain file: "
3741 "<code>%h</code>",
3742 cimi.zParentUuid, zFilename));
3743 }
3744 frid = fast_uuid_to_rid(zFileUuid);
3745 assert(frid);
3746
3747 /* Read file content from submit request or repo... */
@@ -3763,25 +3763,29 @@
3763
3764 fp("<h1>Editing:</h1>");
3765 fp("<p class='fileedit-hint'>");
3766 fp("File: <code>%h</code><br>"
3767 "Version: <code id='r-label'>%s</code><br>",
3768 zFilename, cimi.zParentUuid);
3769 fp("Permalink: <code>"
3770 "<a id='permalink' href='%R/fileedit?file=%T&r=%!S'>"
3771 "/fileedit?file=%T&r=%!S</a></code><br>"
3772 "(Clicking the permalink will reload the page and discard "
3773 "all edits!)",
3774 zFilename, cimi.zParentUuid,
3775 zFilename, cimi.zParentUuid);
3776 fp("</p>");
3777 fp("<p>This page is <em>far from complete</em> and may still have "
3778 "significant bugs. USE AT YOUR OWN RISK, preferably on a test "
3779 "repo.</p>\n");
3780
3781 fp("<form action='%R/fileedit' method='POST' "
3782 "class='fileedit-form'>\n");
3783
3784 /******* Hidden fields *******/
3785 fp("<input type='hidden' name='r' value='%s'>",
3786 cimi.zParentUuid);
3787 fp("<input type='hidden' name='file' value='%T'>",
3788 zFilename);
3789
3790 /******* Comment *******/
3791 fp("<h3>Checkin Comment</h3>\n");
@@ -3924,12 +3928,12 @@
3928 if(zComment && *zComment){
3929 blob_append(&cimi.comment, zComment, -1);
3930 }else{
3931 fail((&err,"Empty comment is not permitted."));
3932 }
3933 /*cimi.pParent = manifest_get(vid, CFTYPE_MANIFEST, 0);
3934 assert(cimi.pParent && "We know vid is valid.");*/
3935 cimi.zFilename = mprintf("%s",zFilename);
3936 cimi.pMfOut = &manifest;
3937 checkin_mini(&cimi, &newVid, &err);
3938 if(newVid!=0){
3939 zNewUuid = rid_to_uuid(newVid);
@@ -3963,13 +3967,15 @@
3967 "link.innerText=urlShort;\n"
3968 "link.setAttribute('href',urlFull);\n",
3969 zFilename, zNewUuid, zFilename, zNewUuid);
3970 }
3971 fossil_free(zNewUuid);
3972 zNewUuid = 0;
3973 }
3974 /* On error, the error message is in the err blob and will
3975 ** be emitted below. */
3976 cimi.pMfOut = 0;
3977 blob_reset(&manifest);
3978 }else if(2==submitMode/*preview*/){
3979 /* TODO */
3980 fail((&err,"Preview mode is still TODO."));
3981 }else if(3==submitMode/*diff*/){
@@ -3979,11 +3985,10 @@
3985 goto end_footer;
3986 }
3987
3988 end_footer:
3989 zContent = 0;
 
3990 fossil_free(zFileUuid);
3991 if(stmt.pStmt){
3992 db_finalize(&stmt);
3993 }
3994 if(blob_size(&err)){
3995

Keyboard Shortcuts

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