Fossil SCM
In the git importer, do not call memset() or qsort() on the list of files when it is empty. The list is then a null pointer, which neither function is declared to accept, and UBSan reported both calls at the start of every import.
Commit
590bf28575041bf54d99ca9a45e43fd539cb039cd36ed085f8610fb57cd5202a
Parent
3e1e91da26268cb…
1 file changed
+2
-2
+2
-2
| --- src/import.c | ||
| +++ src/import.c | ||
| @@ -105,11 +105,11 @@ | ||
| 105 | 105 | for(i=0; i<gg.nFile; i++){ |
| 106 | 106 | fossil_free(gg.aFile[i].zName); |
| 107 | 107 | fossil_free(gg.aFile[i].zUuid); |
| 108 | 108 | fossil_free(gg.aFile[i].zPrior); |
| 109 | 109 | } |
| 110 | - memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0])); | |
| 110 | + if( gg.nFile ) memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0])); | |
| 111 | 111 | gg.nFile = 0; |
| 112 | 112 | if( freeAll ){ |
| 113 | 113 | fossil_free(gg.zPrevBranch); |
| 114 | 114 | fossil_free(gg.zPrevCheckin); |
| 115 | 115 | fossil_free(gg.azMerge); |
| @@ -265,11 +265,11 @@ | ||
| 265 | 265 | char *aTCard[4]; /* Array of T cards for manifest */ |
| 266 | 266 | int nTCard = 0; /* Entries used in aTCard[] */ |
| 267 | 267 | Blob record, cksum; |
| 268 | 268 | |
| 269 | 269 | import_prior_files(); |
| 270 | - qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp); | |
| 270 | + if( gg.nFile ) qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp); | |
| 271 | 271 | blob_zero(&record); |
| 272 | 272 | blob_appendf(&record, "C %F\n", gg.zComment); |
| 273 | 273 | blob_appendf(&record, "D %s\n", gg.zDate); |
| 274 | 274 | if( !g.fQuiet ){ |
| 275 | 275 | fossil_print("%.10s\r", gg.zDate); |
| 276 | 276 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -105,11 +105,11 @@ | |
| 105 | for(i=0; i<gg.nFile; i++){ |
| 106 | fossil_free(gg.aFile[i].zName); |
| 107 | fossil_free(gg.aFile[i].zUuid); |
| 108 | fossil_free(gg.aFile[i].zPrior); |
| 109 | } |
| 110 | memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0])); |
| 111 | gg.nFile = 0; |
| 112 | if( freeAll ){ |
| 113 | fossil_free(gg.zPrevBranch); |
| 114 | fossil_free(gg.zPrevCheckin); |
| 115 | fossil_free(gg.azMerge); |
| @@ -265,11 +265,11 @@ | |
| 265 | char *aTCard[4]; /* Array of T cards for manifest */ |
| 266 | int nTCard = 0; /* Entries used in aTCard[] */ |
| 267 | Blob record, cksum; |
| 268 | |
| 269 | import_prior_files(); |
| 270 | qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp); |
| 271 | blob_zero(&record); |
| 272 | blob_appendf(&record, "C %F\n", gg.zComment); |
| 273 | blob_appendf(&record, "D %s\n", gg.zDate); |
| 274 | if( !g.fQuiet ){ |
| 275 | fossil_print("%.10s\r", gg.zDate); |
| 276 |
| --- src/import.c | |
| +++ src/import.c | |
| @@ -105,11 +105,11 @@ | |
| 105 | for(i=0; i<gg.nFile; i++){ |
| 106 | fossil_free(gg.aFile[i].zName); |
| 107 | fossil_free(gg.aFile[i].zUuid); |
| 108 | fossil_free(gg.aFile[i].zPrior); |
| 109 | } |
| 110 | if( gg.nFile ) memset(gg.aFile, 0, gg.nFile*sizeof(gg.aFile[0])); |
| 111 | gg.nFile = 0; |
| 112 | if( freeAll ){ |
| 113 | fossil_free(gg.zPrevBranch); |
| 114 | fossil_free(gg.zPrevCheckin); |
| 115 | fossil_free(gg.azMerge); |
| @@ -265,11 +265,11 @@ | |
| 265 | char *aTCard[4]; /* Array of T cards for manifest */ |
| 266 | int nTCard = 0; /* Entries used in aTCard[] */ |
| 267 | Blob record, cksum; |
| 268 | |
| 269 | import_prior_files(); |
| 270 | if( gg.nFile ) qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp); |
| 271 | blob_zero(&record); |
| 272 | blob_appendf(&record, "C %F\n", gg.zComment); |
| 273 | blob_appendf(&record, "D %s\n", gg.zDate); |
| 274 | if( !g.fQuiet ){ |
| 275 | fossil_print("%.10s\r", gg.zDate); |
| 276 |