Skip to content

Conversation

@TheChymera
Copy link

@TheChymera TheChymera commented Jan 13, 2024

So the xdg-open command will fire if I call it before the download, but not after. Any ideas what's going on? I can see that the code got there via the debugging line, but it doesn't seem to do anything.


This change is Reviewable

@TheChymera TheChymera marked this pull request as draft January 13, 2024 03:45
usleep(100000);
}
char command[MAX_STR_SIZE];
snprintf(command, sizeof(command), "xdg-open %s", ft->file_path);
Copy link
Member

@Green-Sky Green-Sky Jan 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to mitigate potential command injection, i suggest we sanitize the string and make them url encoded (with the exception of '/')
eg: xdg-open file:///home/green/mpv-shot0001.jpg
or with space: xdg-open file:///home/green/mpv%20shot0001.jpg

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the url encoder could be used for other hyperlinks too.

image

if (mkdir(tmp_dir, S_IRWXU) == -1) {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Could not create tox download /tmp/ directory.\n", err);
}
// end make tmpdir if it does not exist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure what the reasoning behind the temp dir is.

// make and call xdg command
while (ft->state != FILE_TRANSFER_INACTIVE) {
usleep(100000);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are legitimate uses for opening files that are still being transferred (most streaming media types like videos and audio)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sleep will freeze toxic. ft->state can't update while we're in that loop because that function is holding a mutex lock. Sleeps in random functions is almost never the correct solution. They're generally only used in the main loop or in task-specific threads.

@Green-Sky Green-Sky changed the title /fopen command to auto-open downloaded files feat: /fopen command to auto-open downloaded files Jan 13, 2024
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "I am about to run the xdg command.");
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "The file path is '%s'", ft->file_path);

int open_result = popen(command, "r");
Copy link
Member

@nurupo nurupo Jan 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

popen() is a rather dangerous function that does shell interpretation, so it's prone to shell injection. Why not fork() + exec*() instead, calling /usr/bin/xdg-open directly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while I agree with the first statement, said path is not portable.
nixos:

$ which xdg-open
/run/current-system/sw/bin/xdg-open

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ie we would have to search for the binary first (probably once at startup)

@TheChymera
Copy link
Author

superseded by #407

@TheChymera TheChymera closed this Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants