File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 21
21
#include <string.h>
22
22
#include "spx_utils.h"
23
23
24
+ char * spx_utils_resolve_confined_file_absolute_path (
25
+ const char * root_dir ,
26
+ const char * relative_path ,
27
+ const char * suffix ,
28
+ char * dst ,
29
+ size_t size
30
+ ) {
31
+ if (size < PATH_MAX ) {
32
+ spx_utils_die ("size < PATH_MAX" );
33
+ }
34
+
35
+ char absolute_file_path [PATH_MAX ];
36
+
37
+ snprintf (
38
+ absolute_file_path ,
39
+ sizeof (absolute_file_path ),
40
+ "%s%s%s" ,
41
+ root_dir ,
42
+ relative_path ,
43
+ suffix == NULL ? "" : suffix
44
+ );
45
+
46
+ if (realpath (absolute_file_path , dst ) == NULL ) {
47
+ return NULL ;
48
+ }
49
+
50
+ char root_dir_real_path [PATH_MAX ];
51
+ if (realpath (root_dir , root_dir_real_path ) == NULL ) {
52
+ return NULL ;
53
+ }
54
+
55
+ char expected_path_prefix [PATH_MAX + 1 ];
56
+ snprintf (
57
+ expected_path_prefix ,
58
+ sizeof (expected_path_prefix ),
59
+ "%s/" ,
60
+ root_dir_real_path
61
+ );
62
+
63
+ if (! spx_utils_str_starts_with (dst , expected_path_prefix )) {
64
+ return NULL ;
65
+ }
66
+
67
+ return dst ;
68
+ }
69
+
24
70
char * spx_utils_json_escape (char * dst , const char * src , size_t limit )
25
71
{
26
72
size_t i = 0 ;
Original file line number Diff line number Diff line change @@ -50,6 +50,14 @@ do { \
50
50
} \
51
51
} while (0)
52
52
53
+ char * spx_utils_resolve_confined_file_absolute_path (
54
+ const char * root_dir ,
55
+ const char * relative_path ,
56
+ const char * suffix ,
57
+ char * dst ,
58
+ size_t size
59
+ );
60
+
53
61
char * spx_utils_json_escape (char * dst , const char * src , size_t limit );
54
62
int spx_utils_str_starts_with (const char * str , const char * prefix );
55
63
int spx_utils_str_ends_with (const char * str , const char * suffix );
You can’t perform that action at this time.
0 commit comments