libpriv/util: Factor out size limit checking

This will be used in the upcoming patch.

Closes: #1284
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2018-02-22 14:22:21 +00:00 committed by Atomic Bot
parent f6fb505cac
commit d85a1fba0a
3 changed files with 23 additions and 6 deletions

View File

@ -143,12 +143,9 @@ rojig_read_variant (const GVariantType *vtype,
const struct stat *stbuf = archive_entry_stat (entry);
if (!S_ISREG (stbuf->st_mode))
return glnx_null_throw (error, "Expected regular file for entry: %s", path);
if (stbuf->st_size > OSTREE_MAX_METADATA_SIZE)
{
g_autofree char *max_formatted = g_format_size (OSTREE_MAX_METADATA_SIZE);
g_autofree char *found_formatted = g_format_size (stbuf->st_size);
return glnx_null_throw (error, "Exceeded maximum size %s; %s is of size: %s", max_formatted, found_formatted, path);
}
if (!rpmostree_check_size_within_limit (stbuf->st_size, OSTREE_MAX_METADATA_SIZE,
path, error))
return NULL;
g_assert_cmpint (stbuf->st_size, >=, 0);
const size_t total = stbuf->st_size;
g_autofree guint8* buf = g_malloc (total);

View File

@ -234,6 +234,20 @@ rpmostree_pkg_get_local_path (DnfPackage *pkg)
}
}
gboolean
rpmostree_check_size_within_limit (guint64 actual,
guint64 limit,
const char *subject,
GError **error)
{
if (actual <= limit)
return TRUE;
g_autofree char *max_formatted = g_format_size (limit);
g_autofree char *found_formatted = g_format_size (actual);
return glnx_throw (error, "Exceeded maximum size %s; %s is of size: %s",
max_formatted, subject, found_formatted);
}
/* Convert a "traditional" path (normally from e.g. an RPM) into its final location in
* ostree */
char*

View File

@ -68,6 +68,12 @@ rpmostree_pkg_is_local (DnfPackage *pkg);
char *
rpmostree_pkg_get_local_path (DnfPackage *pkg);
gboolean
rpmostree_check_size_within_limit (guint64 actual,
guint64 limit,
const char *subject,
GError **error);
char*
rpmostree_translate_path_for_ostree (const char *path);