File tree Expand file tree Collapse file tree 3 files changed +41
-33
lines changed Expand file tree Collapse file tree 3 files changed +41
-33
lines changed Original file line number Diff line number Diff line change @@ -1795,45 +1795,13 @@ SEXP_t *probe_obj_getmask(SEXP_t *obj)
1795
1795
return (mask );
1796
1796
}
1797
1797
1798
- static bool path_startswith (const char * path , const char * prefix )
1799
- {
1800
- bool res = true;
1801
- const char * del = "/" ;
1802
- char * path_dup = oscap_strdup (path );
1803
- char * * path_split = oscap_split (path_dup , del );
1804
- char * prefix_dup = oscap_strdup (prefix );
1805
- char * * prefix_split = oscap_split (prefix_dup , del );
1806
- int i = 0 , j = 0 ;
1807
- while (prefix_split [i ] && path_split [j ]) {
1808
- if (!strcmp (prefix_split [i ], "" )) {
1809
- ++ i ;
1810
- continue ;
1811
- }
1812
- if (!strcmp (path_split [j ], "" )) {
1813
- ++ j ;
1814
- continue ;
1815
- }
1816
- if (strcmp (prefix_split [i ], path_split [j ])) {
1817
- res = false;
1818
- break ;
1819
- }
1820
- ++ i ;
1821
- ++ j ;
1822
- }
1823
- free (path_dup );
1824
- free (path_split );
1825
- free (prefix_dup );
1826
- free (prefix_split );
1827
- return res ;
1828
- }
1829
-
1830
1798
bool probe_path_is_blocked (const char * path , struct oscap_list * blocked_paths )
1831
1799
{
1832
1800
bool res = false;
1833
1801
struct oscap_iterator * it = oscap_iterator_new (blocked_paths );
1834
1802
while (oscap_iterator_has_more (it )) {
1835
1803
const char * item = oscap_iterator_next (it );
1836
- if (path_startswith (path , item )) {
1804
+ if (oscap_path_startswith (path , item )) {
1837
1805
res = true;
1838
1806
break ;
1839
1807
}
Original file line number Diff line number Diff line change @@ -442,3 +442,35 @@ int oscap_open_writable(const char *filename)
442
442
}
443
443
return fd ;
444
444
}
445
+
446
+ bool oscap_path_startswith (const char * path , const char * prefix )
447
+ {
448
+ bool res = true;
449
+ const char * del = "/" ;
450
+ char * path_dup = oscap_strdup (path );
451
+ char * * path_split = oscap_split (path_dup , del );
452
+ char * prefix_dup = oscap_strdup (prefix );
453
+ char * * prefix_split = oscap_split (prefix_dup , del );
454
+ int i = 0 , j = 0 ;
455
+ while (prefix_split [i ] && path_split [j ]) {
456
+ if (!strcmp (prefix_split [i ], "" )) {
457
+ ++ i ;
458
+ continue ;
459
+ }
460
+ if (!strcmp (path_split [j ], "" )) {
461
+ ++ j ;
462
+ continue ;
463
+ }
464
+ if (strcmp (prefix_split [i ], path_split [j ])) {
465
+ res = false;
466
+ break ;
467
+ }
468
+ ++ i ;
469
+ ++ j ;
470
+ }
471
+ free (path_dup );
472
+ free (path_split );
473
+ free (prefix_dup );
474
+ free (prefix_split );
475
+ return res ;
476
+ }
Original file line number Diff line number Diff line change @@ -540,4 +540,12 @@ char *oscap_windows_error_message(unsigned long error_code);
540
540
*/
541
541
int oscap_open_writable (const char * filename );
542
542
543
+ /**
544
+ * Check if a path starts with the given prefix
545
+ * @param path file system path
546
+ * @param prefix file system path that will be tested if it's a prefix of the path parameter
547
+ * @return true or false
548
+ */
549
+ bool oscap_path_startswith (const char * path , const char * prefix );
550
+
543
551
#endif /* OSCAP_UTIL_H_ */
You can’t perform that action at this time.
0 commit comments