Skip to content

Commit

Permalink
properly escape media info payload
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Jan 11, 2024
1 parent 7021a98 commit 6ff8ffa
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/media.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ - (id)init {
- (void) update {
@autoreleasepool {
if (self.app && self.artist && self.title && self.album) {
char* escaped_artist = escape_string((char*)self.artist);
char* escaped_title = escape_string((char*)self.title);
char* escaped_album = escape_string((char*)self.album);

uint32_t info_len = strlen(self.app)
+ strlen(self.artist)
+ strlen(self.title)
+ strlen(self.album) + 256;
+ strlen(escaped_artist)
+ strlen(escaped_title)
+ strlen(escaped_album) + 256;

char info[info_len];
snprintf(info, info_len, "{\n"
Expand All @@ -71,11 +75,15 @@ - (void) update {
"\t\"artist\": \"%s\",\n"
"\t\"app\": \"%s\"\n}",
self.playing ? "playing" : "paused",
self.title,
self.album,
self.artist,
escaped_title,
escaped_album,
escaped_artist,
self.app );

free(escaped_artist);
free(escaped_title);
free(escaped_album);

if (self.artwork) {
struct event cover_event = { self.artwork, COVER_CHANGED };
event_post(&cover_event);
Expand Down

0 comments on commit 6ff8ffa

Please sign in to comment.