mirror of https://github.com/djcb/mu.git
mu: fix strncpy usage
Ensure the resulting strings are \0-terminated.
This commit is contained in:
parent
088064d5e1
commit
2d954e9647
|
@ -225,14 +225,17 @@ mu_contacts_clear (MuContacts *self)
|
||||||
static const char*
|
static const char*
|
||||||
encode_email_address (const char *addr)
|
encode_email_address (const char *addr)
|
||||||
{
|
{
|
||||||
static char enc[254 + 1]; /* max size for an e-mail addr */
|
static char enc[254 + 1]; /* max size for an e-mail addr */
|
||||||
char *cur;
|
char *cur;
|
||||||
|
|
||||||
if (!addr)
|
if (!addr)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
cur = strncpy(enc, addr, sizeof(enc) - 1);
|
||||||
|
cur[sizeof(enc) - 1] = '\0';
|
||||||
|
|
||||||
/* make sure chars are with {' ' .. '~'}, and not '[' ']' */
|
/* make sure chars are with {' ' .. '~'}, and not '[' ']' */
|
||||||
for (cur = strncpy(enc, addr, sizeof(enc)); *cur != '\0'; ++cur)
|
for (; *cur != '\0'; ++cur)
|
||||||
if (!isalnum(*cur)) {
|
if (!isalnum(*cur)) {
|
||||||
*cur = 'A' + (*cur % ('Z' - 'A'));
|
*cur = 'A' + (*cur % ('Z' - 'A'));
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -54,8 +54,10 @@ mu_date_str_s (const char* frm, time_t t)
|
||||||
g_warning ("conversion failed: %s", err->message);
|
g_warning ("conversion failed: %s", err->message);
|
||||||
g_error_free (err);
|
g_error_free (err);
|
||||||
strcpy (buf, "<error>");
|
strcpy (buf, "<error>");
|
||||||
} else
|
} else {
|
||||||
strncpy (buf, conv, sizeof(buf));
|
strncpy (buf, conv, sizeof(buf)-1);
|
||||||
|
buf[sizeof(buf)-1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
g_free (conv);
|
g_free (conv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,7 +344,8 @@ field_string_list (MuMsg *msg, MuMsgFieldId mfid)
|
||||||
|
|
||||||
str = mu_str_from_list (lst, ',');
|
str = mu_str_from_list (lst, ',');
|
||||||
if (str) {
|
if (str) {
|
||||||
strncpy (buf, str, sizeof(buf));
|
strncpy (buf, str, sizeof(buf)-1);
|
||||||
|
buf[sizeof(buf)-1]='\0';
|
||||||
g_free (str);
|
g_free (str);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1406,7 +1406,8 @@ get_path_from_docid (MuStore *store, unsigned docid, GError **err)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy (path, msgpath, sizeof(path));
|
strncpy (path, msgpath, sizeof(path) - 1);
|
||||||
|
path[sizeof(path)-1] = '\0';
|
||||||
|
|
||||||
mu_msg_unref (msg);
|
mu_msg_unref (msg);
|
||||||
return path;
|
return path;
|
||||||
|
|
Loading…
Reference in New Issue