Skip to content

Commit

Permalink
truncate overlong messages (fixes dunst-project#248)
Browse files Browse the repository at this point in the history
Displaying too heavy notifications can DoS dunst. For example bad
programs, which pipe raw image data into the notification.
Limiting the maximum character length to 5000 circumvents this.

5000 should be ridiculously high to prevent DoS while still not
truncating all correct notifications.
  • Loading branch information
bebehei committed Jul 9, 2017
1 parent a08fba4 commit 717c747
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Text and icons are now centred vertically
- Notifications aren't considered duplicate if urgency or icons differ
- The frame width and color settings were moved to the global section as frame\_width and frame\_color respectively.
- The maximum displayed field length is limited to 5000 characters

### Deprecated
- `allow_markup` will be removed in later versions. It is being replaced by `markup`
Expand Down
10 changes: 10 additions & 0 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ int notification_init(notification * n, int id)

n->msg = g_strchomp(n->msg);

/* truncate overlong messages */
if (strlen(n->msg) > DUNST_NOTIF_MAX_CHARS) {
char* buffer = g_malloc(DUNST_NOTIF_MAX_CHARS);
strncpy(buffer, n->msg, DUNST_NOTIF_MAX_CHARS);
buffer[DUNST_NOTIF_MAX_CHARS-1] = '\0';

g_free(n->msg);
n->msg = buffer;
}

if (n->icon != NULL && strlen(n->icon) <= 0) {
g_free(n->icon);
n->icon = NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#define NORM 1
#define CRIT 2

#define DUNST_NOTIF_MAX_CHARS 5000

typedef struct _raw_image {
int width;
int height;
Expand Down

0 comments on commit 717c747

Please sign in to comment.