@@ -19,9 +19,9 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
1919 if (!ffStrEndsWith (entry -> d_name , "-event-kbd" ))
2020 continue ;
2121
22- char buffer [32 ]; // `../eventX `
22+ char buffer [32 ]; // `../eventXX `
2323 ssize_t len = readlinkat (dirfd (dirp ), entry -> d_name , buffer , ARRAY_SIZE (buffer ) - 1 );
24- if (len != strlen ("../eventX " ) || !ffStrStartsWith (buffer , "../event" )) continue ;
24+ if (len <= ( ssize_t ) strlen ("../event " ) || !ffStrStartsWith (buffer , "../event" )) continue ;
2525 buffer [len ] = 0 ;
2626
2727 const char * eventid = buffer + strlen ("../event" );
@@ -30,8 +30,8 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
3030 uint32_t index = (uint32_t ) strtoul (eventid , & pend , 10 );
3131 if (pend == eventid ) continue ;
3232
33- // Ignore duplicate entries
34- if (flags & (1UL << index ))
33+ // Ignore duplicate entries (flags supports up to 64 event indices)
34+ if (index >= 64 || ( flags & (1UL << index ) ))
3535 continue ;
3636 flags |= (1UL << index );
3737
@@ -41,7 +41,7 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
4141 if (ffAppendFileBuffer (path .chars , & name ))
4242 {
4343 ffStrbufTrimRightSpace (& name );
44- ffStrbufSubstrBefore (& path , path .length - 4 );
44+ ffStrbufSubstrBefore (& path , path .length - ( uint32_t ) strlen ( "name" ) );
4545
4646 FFKeyboardDevice * device = (FFKeyboardDevice * ) ffListAdd (devices );
4747 ffStrbufInitMove (& device -> name , & name );
0 commit comments