@@ -621,19 +621,46 @@ FF_MAYBE_UNUSED static void detectSocName(FFCPUResult* cpu)
621621 if (cpu -> name .length > 0 )
622622 return ;
623623
624- // device -vendor,device -model\0soc-vendor,soc-model\0
625- char content [256 ];
624+ // [x -vendor,x -model\0]*N
625+ char content [512 ];
626626 ssize_t length = ffReadFileData ("/proc/device-tree/compatible" , ARRAY_SIZE (content ), content );
627- if (length <= 2 ) return ;
627+ if (length < 4 ) return ; // v,m\0
628628
629- // get the second NUL terminated string if it exists
630- char * vendor = memchr (content , '\0' , (size_t ) length ) + 1 ;
631- if (!vendor || vendor - content >= length ) vendor = content ;
629+ if (content [length - 1 ] != '\0' ) return ; // must end with \0
632630
633- char * model = strchr (vendor , ',' );
634- if (!model ) return ;
635- * model = '\0' ;
636- ++ model ;
631+ -- length ;
632+
633+ char * vendor = NULL ;
634+ char * model = NULL ;
635+
636+ for (char * p ; length > 0 ; length = p ? (ssize_t ) (p - content ) - 1 : 0 )
637+ {
638+ p = memrchr (content , '\0' , (size_t ) length );
639+
640+ vendor = p /* first entry */ ? p + 1 : content ;
641+
642+ size_t partLen = (size_t ) (length - (vendor - content ));
643+ if (partLen < 3 ) continue ;
644+
645+ char * comma = memchr (vendor , ',' , partLen );
646+ if (!comma ) continue ;
647+
648+ size_t vendorLen = (size_t ) (comma - vendor );
649+ if (vendorLen == 0 ) continue ;
650+
651+ model = comma + 1 ;
652+ size_t modelLen = (size_t ) (partLen - (size_t ) (model - vendor ));
653+ if (modelLen == 0 ) continue ;
654+
655+ if ((modelLen >= strlen ("-platform" ) && ffStrEndsWith (model , "-platform" )) ||
656+ (modelLen >= strlen ("-soc" ) && ffStrEndsWith (model , "-soc" )))
657+ continue ;
658+
659+ * comma = '\0' ;
660+ break ;
661+ }
662+
663+ if (!length ) return ;
637664
638665 if (false) {}
639666 #if __aarch64__
0 commit comments