- commit
- f9c1ec414b69f383b42ef050405da550a5c52235
- parent
- 408dbe50bbe489b2864b9408289f1b5d00ee855b
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2026-03-15 09:02
[OpenURI] properly handle URI encoding
Diffstat
| M | OpenURI/open-uri.c | 17 | +++++++++++++---- |
1 files changed, 13 insertions, 4 deletions
diff --git a/OpenURI/open-uri.c b/OpenURI/open-uri.c
@@ -25,6 +25,13 @@ int get_pidfd(int sock) {
25 25 return pidfd;
26 26 }
27 27
-1 28 char *uri_to_path(char *uri) {
-1 29 GFile *file = g_file_new_for_uri(uri);
-1 30 char *path = g_file_get_path(file);
-1 31 g_object_unref(file);
-1 32 return path;
-1 33 }
-1 34
28 35 int is_readable(int fd) {
29 36 fd_set fds;
30 37 struct timeval timeout;
@@ -66,17 +73,17 @@ int stat_at_root(const char *path, const char *root, struct stat *statbuf) {
66 73 return 0;
67 74 }
68 75
69 -1 int same_on_host(char *uri, int pidfd) {
-1 76 int same_on_host(char *path, int pidfd) {
70 77 char root_sender[32];
71 78 struct stat s_sender, s_host;
72 79
73 80 snprintf(
74 81 root_sender, sizeof(root_sender), "/proc/%i/root/", pidfd_getpid(pidfd)
75 82 );
76 -1 if (stat_at_root(uri + 7, root_sender, &s_sender) != 0) {
-1 83 if (stat_at_root(path, root_sender, &s_sender) != 0) {
77 84 return -1;
78 85 }
79 -1 if (stat_at_root(uri + 7, "/", &s_host) != 0) {
-1 86 if (stat_at_root(path, "/", &s_host) != 0) {
80 87 return -1;
81 88 }
82 89 if (s_sender.st_dev != s_host.st_dev || s_sender.st_ino != s_host.st_ino) {
@@ -105,9 +112,11 @@ int main() {
105 112 if (pidfd < 0) {
106 113 return EXIT_FAILURE;
107 114 }
108 -1 if (same_on_host(uri, pidfd) != 0) {
-1 115 char *path = uri_to_path(uri);
-1 116 if (same_on_host(path, pidfd) != 0) {
109 117 return EXIT_FAILURE;
110 118 }
-1 119 free(path);
111 120 }
112 121
113 122 GError *error = NULL;