commit dfe2ad9662a4763c47a79b3f907e4d33c6d3536d from: Omar Polo date: Thu Feb 24 08:26:56 2022 UTC don't crash when trying to play a directory with pledge(sendfd) we can't send a fd that represents a directory, so we have to check before and eventually skip. commit - c4a8987ff963246782c67693fba85acb5ad7b41e commit + dfe2ad9662a4763c47a79b3f907e4d33c6d3536d blob - 56aea43e121542cf119487af5bdd22c5cf02cb34 blob + b74f792e8186849c3c42f05b095a2acbe32adae8 --- amused.c +++ amused.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -353,15 +354,28 @@ main_send_player(uint16_t type, int fd, const void *da int main_play_song(const char *song) { + struct stat sb; char path[PATH_MAX] = { 0 }; int fd; strlcpy(path, song, sizeof(path)); if ((fd = open(path, O_RDONLY)) == -1) { log_warn("open %s", path); + return 0; + } + + if (fstat(fd, &sb) == -1) { + log_warn("failed to stat %s", path); + close(fd); return 0; } + if (S_ISDIR(sb.st_mode)) { + log_info("skipping a directory: %s", path); + close(fd); + return 0; + } + play_state = STATE_PLAYING; imsg_compose_event(iev_player, IMSG_PLAY, 0, 0, fd, path, sizeof(path));