mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-08 07:26:16 +00:00
Reserve enough memory when storing a DC's nickname
in gtk-gui.c: The input text field in set_dc_nickname() has a limit of 68 unicode characters, which are 136 bytes. In remember_dc(), to make sure that this nickname, the deviceid (4 bytes) and also the extra characters (",{}") always fit wihout truncation (from snprintf) in the allocated stack buffer, we increase the size of the buffer to 256 bytes. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
371ace39b5
commit
be9d924cf8
1 changed files with 2 additions and 2 deletions
|
@ -2043,7 +2043,7 @@ static char *cleanedup_nickname(const char *nickname, int len)
|
||||||
void remember_dc(uint32_t deviceid, const char *nickname, gboolean change_conf)
|
void remember_dc(uint32_t deviceid, const char *nickname, gboolean change_conf)
|
||||||
{
|
{
|
||||||
if (!get_dc_nickname(deviceid)) {
|
if (!get_dc_nickname(deviceid)) {
|
||||||
char buffer[80];
|
char buffer[256];
|
||||||
struct dcnicknamelist *nn_entry = malloc(sizeof(struct dcnicknamelist));
|
struct dcnicknamelist *nn_entry = malloc(sizeof(struct dcnicknamelist));
|
||||||
nn_entry->deviceid = deviceid;
|
nn_entry->deviceid = deviceid;
|
||||||
/* make sure there are no curly braces or commas in the string and that
|
/* make sure there are no curly braces or commas in the string and that
|
||||||
|
@ -2051,7 +2051,7 @@ void remember_dc(uint32_t deviceid, const char *nickname, gboolean change_conf)
|
||||||
nn_entry->nickname = cleanedup_nickname(nickname, sizeof(buffer) - 12);
|
nn_entry->nickname = cleanedup_nickname(nickname, sizeof(buffer) - 12);
|
||||||
nn_entry->next = nicknamelist;
|
nn_entry->next = nicknamelist;
|
||||||
nicknamelist = nn_entry;
|
nicknamelist = nn_entry;
|
||||||
snprintf(buffer, 80, "{%08x,%s}", deviceid, nn_entry->nickname);
|
snprintf(buffer, sizeof(buffer), "{%08x,%s}", deviceid, nn_entry->nickname);
|
||||||
nicknamestring = realloc(nicknamestring, strlen(nicknamestring) + strlen(buffer) + 1);
|
nicknamestring = realloc(nicknamestring, strlen(nicknamestring) + strlen(buffer) + 1);
|
||||||
strcat(nicknamestring, buffer);
|
strcat(nicknamestring, buffer);
|
||||||
if (change_conf)
|
if (change_conf)
|
||||||
|
|
Loading…
Add table
Reference in a new issue