View Issue Details

IDProjectCategoryView StatusLast Update
0000209fileGeneralpublic2020-12-16 23:38
ReporterHelflym Assigned Tochristos  
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
Product Version5.39 
Fixed in Version5.40 
Summary0000209: apprentice.c:coalesce_entries can call malloc with a 0 size
DescriptionHi,

When running "regex-eol", it happens that coalesce_entries is called with "nme = 0". Thus, "mentrycount" will be 0 and the malloc for "**ma" will be called with "slen = 0".
In most of the OSes, it does work and will return a pointer, but on AIX, it's not allowed and will raise a ENOMEM error.

I've made a patch to avoid calling coalesce_entries if there is no entries and it seems to work fine (all tests are OK).
It seems the logical approach to me. But I want to be sure that it's the correct way to fix it or if it would be better to still allocate a pointer even when there is no entries, as it's done right now on Linux.

Thanks,
TagsNo tags attached.

Activities

Helflym

2020-11-13 10:44

reporter  

file-5.39-avoid-coalesce_entries-when-there-is-no-entries.patch (457 bytes)   
--- a/src/apprentice.c	2020-11-13 11:14:12 +0100
+++ b/src/apprentice.c	2020-11-13 11:14:21 +0100
@@ -1461,7 +1461,10 @@
 		 */
 		set_last_default(ms, mset[j].me, mset[j].count);
 
-		/* coalesce per file arrays into a single one */
+		/* coalesce per file arrays into a single one, if needed */
+		if (mset[j].count == 0)
+		  continue;
+
 		if (coalesce_entries(ms, mset[j].me, mset[j].count,
 		    &map->magic[j], &map->nmagic[j]) == -1) {
 			errs++;

christos

2020-12-16 23:38

manager   ~0003505

Fixed, thanks!

Issue History

Date Modified Username Field Change
2020-11-13 10:44 Helflym New Issue
2020-11-13 10:44 Helflym File Added: file-5.39-avoid-coalesce_entries-when-there-is-no-entries.patch
2020-12-16 23:38 christos Assigned To => christos
2020-12-16 23:38 christos Status new => assigned
2020-12-16 23:38 christos Status assigned => resolved
2020-12-16 23:38 christos Resolution open => fixed
2020-12-16 23:38 christos Fixed in Version => 5.40
2020-12-16 23:38 christos Note Added: 0003505