Commit 44daf808 authored by Timo Teräs's avatar Timo Teräs

fix strncpy bounds errors

error: 'strncpy' specified bound 4096 equals destination size [-Werror=stringop-truncation]

Based on patch by Elan Ruusamäe <glen@delfi.ee>
parent 86922d1a
......@@ -496,10 +496,10 @@ http_next_header(conn_t *conn, const char **p)
static int
http_parse_mtime(const char *p, time_t *mtime)
{
char locale[64], *r;
char *locale, *r;
struct tm tm;
strncpy(locale, setlocale(LC_TIME, NULL), sizeof(locale));
locale = strdupa(setlocale(LC_TIME, NULL));
setlocale(LC_TIME, "C");
r = strptime(p, "%a, %d %b %Y %H:%M:%S GMT", &tm);
/* XXX should add support for date-2 and date-3 */
......
......@@ -133,4 +133,8 @@ void apk_atom_init(void);
apk_blob_t *apk_blob_atomize(apk_blob_t blob);
apk_blob_t *apk_blob_atomize_dup(apk_blob_t blob);
#if defined(__GLIBC__) && !defined(__UCLIBC__)
extern size_t strlcpy(char *dest, const char *src, size_t size);
#endif
#endif
......@@ -387,10 +387,10 @@ int apk_tar_write_entry(struct apk_ostream *os, const struct apk_file_info *ae,
return -1;
if (ae->name != NULL)
strncpy(buf.name, ae->name, sizeof(buf.name));
strlcpy(buf.name, ae->name, sizeof buf.name);
strncpy(buf.uname, ae->uname ?: "root", sizeof(buf.uname));
strncpy(buf.gname, ae->gname ?: "root", sizeof(buf.gname));
strlcpy(buf.uname, ae->uname ?: "root", sizeof buf.uname);
strlcpy(buf.gname, ae->gname ?: "root", sizeof buf.gname);
PUT_OCTAL(buf.size, ae->size);
PUT_OCTAL(buf.uid, ae->uid);
......
......@@ -717,3 +717,16 @@ apk_blob_t *apk_blob_atomize_dup(apk_blob_t blob)
return &atom->blob;
}
#if defined(__GLIBC__) && !defined(__UCLIBC__)
size_t strlcpy(char *dst, const char *src, size_t size)
{
size_t ret = strlen(src), len;
if (!size) return ret;
len = ret;
if (len >= size) len = size - 1;
memcpy(dest, src, len);
dst[len] = 0;
return ret;
}
#endif
......@@ -2787,7 +2787,10 @@ static int apk_db_unpack_pkg(struct apk_database *db,
if (!(pkg->repos & db->local_repos))
need_copy = TRUE;
} else {
strncpy(file, pkg->filename, sizeof(file));
if (strlcpy(file, pkg->filename, sizeof file) >= sizeof file) {
r = -ENAMETOOLONG;
goto err_msg;
}
need_copy = TRUE;
}
if (!apk_db_cache_active(db))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment