@@ -358,6 +358,19 @@ main(int argc,
358358
359359/* local subsystem functions */
360360#ifdef HAVE_EEZE_MOUNT
361+
362+ static Eina_Bool
363+ check_is_num_to_comma (const char * s )
364+ {
365+ const char * p ;
366+
367+ for (p = s ; * p && (* p != ',' ); p ++ )
368+ {
369+ if (!((* p >= '0' ) && (* p <= '9' ))) return EINA_FALSE ;
370+ }
371+ return EINA_TRUE ;
372+ }
373+
361374static Eina_Bool
362375mountopts_check (const char * opts )
363376{
@@ -400,6 +413,8 @@ mountopts_check(const char *opts)
400413 {
401414 p += 4 ;
402415 errno = 0 ;
416+
417+ if (!check_is_num_to_comma (p )) return EINA_FALSE ;
403418 muid = strtoul (p , & end , 10 );
404419 if (muid == ULONG_MAX ) return EINA_FALSE ;
405420 if (errno ) return EINA_FALSE ;
@@ -414,23 +429,63 @@ mountopts_check(const char *opts)
414429 return EINA_TRUE ;
415430}
416431
432+ static Eina_Bool
433+ check_is_alpha_num (char c )
434+ {
435+ if (((c >= '0' ) && (c <= '9' )) ||
436+ ((c >= 'a' ) && (c <= 'z' )) ||
437+ ((c >= 'A' ) && (c <= 'Z' ))) return EINA_TRUE ;
438+ return EINA_FALSE ;
439+ }
440+
417441static Eina_Bool
418442check_uuid (const char * uuid )
419443{
420444 const char * p ;
421445
422446 for (p = uuid ; p [0 ]; p ++ )
423- if ((!isalnum (* p )) && (* p != '-' )) return EINA_FALSE ;
447+ {
448+ if ((!check_is_alpha_num (* p )) && (* p != '-' )) return EINA_FALSE ;
449+ }
450+ return EINA_TRUE ;
451+ }
452+
453+ static Eina_Bool
454+ check_sane_path (const char * path )
455+ {
456+ const char * forbidden_ch = "`~!#$%^&*()[]{}|\\;'\"<>?" ;
457+ const char * p ;
458+
459+ if (strstr (path , ".." )) return EINA_FALSE ; // just don't allow .. anywhere
460+ for (p = forbidden_ch ; * p ; p ++ ) // no invalid chars like above
461+ {
462+ if (strchr (path , * p )) return EINA_FALSE ;
463+ }
464+ for (p = path ; * p ; p ++ ) // nothing in lower ascii ctrl chars or high ascii
465+ {
466+ if ((* p <= ' ' ) || (* p >= 0x7f )) return EINA_FALSE ;
467+ }
468+ return EINA_TRUE ;
469+ }
470+
471+ static Eina_Bool
472+ check_sane_dev (const char * dev )
473+ {
474+ struct stat st ;
475+
476+ if (strncmp (dev , "/dev/" , 5 )) return EINA_FALSE ; // not a /dev file
477+ if (!check_sane_path (dev )) return EINA_FALSE ;
478+ if (stat (dev , & st )) return EINA_FALSE ; // must actually exist
424479 return EINA_TRUE ;
425480}
426481
427482static Eina_Bool
428483mount_args_check (int argc , char * * argv , const char * action )
429484{
430485 Eina_Bool opts = EINA_FALSE ;
431- struct stat st ;
432486 const char * node ;
433487 char buf [PATH_MAX ];
488+ struct stat st ;
434489
435490 if (!strcmp (action , "mount" ))
436491 {
@@ -451,9 +506,9 @@ mount_args_check(int argc, char **argv, const char *action)
451506 }
452507 else
453508 {
454- if (strncmp (argv [4 ], "/dev/" , 5 )) return EINA_FALSE ;
455- if (stat (argv [4 ], & st )) return EINA_FALSE ;
509+ if (!check_sane_dev (argv [4 ])) return EINA_FALSE ;
456510 }
511+ if (!check_sane_path (argv [5 ])) return EINA_FALSE ;
457512
458513 node = strrchr (argv [5 ], '/' );
459514 if (!node ) return EINA_FALSE ;
@@ -468,8 +523,7 @@ mount_args_check(int argc, char **argv, const char *action)
468523 /path/to/umount /dev/$devnode
469524 */
470525 if (argc != 3 ) return EINA_FALSE ;
471- if (strncmp (argv [2 ], "/dev/" , 5 )) return EINA_FALSE ;
472- if (stat (argv [2 ], & st )) return EINA_FALSE ;
526+ if (!check_sane_dev (argv [2 ])) return EINA_FALSE ;
473527 node = strrchr (argv [2 ], '/' );
474528 if (!node ) return EINA_FALSE ;
475529 if (!node [1 ]) return EINA_FALSE ;
@@ -488,8 +542,7 @@ mount_args_check(int argc, char **argv, const char *action)
488542 /path/to/eject /dev/$devnode
489543 */
490544 if (argc != 3 ) return EINA_FALSE ;
491- if (strncmp (argv [2 ], "/dev/" , 5 )) return EINA_FALSE ;
492- if (stat (argv [2 ], & st )) return EINA_FALSE ;
545+ if (!check_sane_dev (argv [2 ])) return EINA_FALSE ;
493546 node = strrchr (argv [2 ], '/' );
494547 if (!node ) return EINA_FALSE ;
495548 if (!node [1 ]) return EINA_FALSE ;
0 commit comments