mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Prevent garbage from being saved in the userid field
It seems that in some scenarios we end up with a string that isn't NUL terminated and that results in garbage being stored as userid. This patch is a little brute force but it fixes the problem even if a previous version os Subsurface ended up adding other text to the end of the userid. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
21675de534
commit
2f7a7f3e6a
3 changed files with 4 additions and 2 deletions
2
dive.c
2
dive.c
|
@ -2720,6 +2720,8 @@ void set_save_userid_local(short value)
|
||||||
void set_userid(char *rUserId)
|
void set_userid(char *rUserId)
|
||||||
{
|
{
|
||||||
prefs.userid = strdup(rUserId);
|
prefs.userid = strdup(rUserId);
|
||||||
|
if (strlen(prefs.userid) > 30)
|
||||||
|
prefs.userid[30]='\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
int average_depth(struct diveplan *dive)
|
int average_depth(struct diveplan *dive)
|
||||||
|
|
|
@ -754,7 +754,7 @@ static void save_userid(void *_b)
|
||||||
{
|
{
|
||||||
struct membuffer *b = _b;
|
struct membuffer *b = _b;
|
||||||
if (prefs.save_userid_local)
|
if (prefs.save_userid_local)
|
||||||
put_format(b, "userid %30s", prefs.userid);
|
put_format(b, "userid %30s\n", prefs.userid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void save_one_device(void *_b, const char *model, uint32_t deviceid,
|
static void save_one_device(void *_b, const char *model, uint32_t deviceid,
|
||||||
|
|
|
@ -520,7 +520,7 @@ void save_dives_buffer(struct membuffer *b, const bool select_only)
|
||||||
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION);
|
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION);
|
||||||
|
|
||||||
if (prefs.save_userid_local)
|
if (prefs.save_userid_local)
|
||||||
put_format(b, " <userid>%s</userid>\n", prefs.userid);
|
put_format(b, " <userid>%30s</userid>\n", prefs.userid);
|
||||||
|
|
||||||
/* save the dive computer nicknames, if any */
|
/* save the dive computer nicknames, if any */
|
||||||
call_for_each_dc(b, save_one_device);
|
call_for_each_dc(b, save_one_device);
|
||||||
|
|
Loading…
Add table
Reference in a new issue