static-delta: add some error handling
We make _ostree_parse_delta_name() a bit more defensive since it handles user input. Closes: #504 Closes: #505 Approved by: cgwalters
This commit is contained in:
1 parent
36e8ba124e
commit
12e916466c
6 files changed
+77
-21
No files matched your search
@@ -121,10 +121,11 @@ static inline char * _ostree_get_commitpartial_path (const char *checksum)
|
||||
return g_strconcat ("state/", checksum, ".commitpartial", NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gboolean
|
||||
_ostree_parse_delta_name (const char *delta_name,
|
||||
char **out_from,
|
||||
char **out_to);
|
||||
char **out_to,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
_ostree_loose_path (char *buf,
|
||||
|
||||
@@ -1584,12 +1584,26 @@ _ostree_get_relative_static_delta_part_path (const char *from,
|
||||
return _ostree_get_relative_static_delta_path (from, to, partstr);
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_parse_delta_name (const char *delta_name,
|
||||
gboolean
|
||||
_ostree_parse_delta_name (const char *delta_name,
|
||||
char **out_from,
|
||||
char **out_to)
|
||||
char **out_to,
|
||||
GError **error)
|
||||
{
|
||||
g_auto(GStrv) parts = g_strsplit (delta_name, "-", 2);
|
||||
g_auto(GStrv) parts = NULL;
|
||||
g_return_val_if_fail (delta_name != NULL, FALSE);
|
||||
|
||||
parts = g_strsplit (delta_name, "-", 2);
|
||||
|
||||
/* NB: if delta_name is "", parts[0] is NULL, but the error
|
||||
* validate_checksum_string() gives for "" is nice enough,
|
||||
* so we just coerce it here */
|
||||
if (!ostree_validate_checksum_string (parts[0] ?: "", error))
|
||||
return FALSE;
|
||||
|
||||
if (parts[0] && parts[1] &&
|
||||
!ostree_validate_checksum_string (parts[1], error))
|
||||
return FALSE;
|
||||
|
||||
*out_from = *out_to = NULL;
|
||||
if (parts[0] && parts[1])
|
||||
@@ -1601,6 +1615,8 @@ _ostree_parse_delta_name (const char *delta_name,
|
||||
{
|
||||
ot_transfer_out_value (out_to, &parts[0]);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -795,7 +795,9 @@ _ostree_repo_static_delta_delete (OstreeRepo *self,
|
||||
g_autofree char *deltadir = NULL;
|
||||
struct stat buf;
|
||||
|
||||
_ostree_parse_delta_name (delta_id, &from, &to);
|
||||
if (!_ostree_parse_delta_name (delta_id, &from, &to, error))
|
||||
goto out;
|
||||
|
||||
deltadir = _ostree_get_relative_static_delta_path (from, to, NULL);
|
||||
|
||||
if (fstatat (self->repo_dir_fd, deltadir, &buf, 0) != 0)
|
||||
@@ -830,7 +832,9 @@ _ostree_repo_static_delta_query_exists (OstreeRepo *self,
|
||||
g_autofree char *superblock_path = NULL;
|
||||
struct stat stbuf;
|
||||
|
||||
_ostree_parse_delta_name (delta_id, &from, &to);
|
||||
if (!_ostree_parse_delta_name (delta_id, &from, &to, error))
|
||||
return FALSE;
|
||||
|
||||
superblock_path = _ostree_get_relative_static_delta_superblock_path (from, to);
|
||||
|
||||
if (fstatat (self->repo_dir_fd, superblock_path, &stbuf, 0) < 0)
|
||||
@@ -854,7 +858,7 @@ gboolean
|
||||
_ostree_repo_static_delta_dump (OstreeRepo *self,
|
||||
const char *delta_id,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
g_autofree char *from = NULL;
|
||||
@@ -868,7 +872,9 @@ _ostree_repo_static_delta_dump (OstreeRepo *self,
|
||||
OstreeDeltaEndianness endianness;
|
||||
gboolean swap_endian = FALSE;
|
||||
|
||||
_ostree_parse_delta_name (delta_id, &from, &to);
|
||||
if (!_ostree_parse_delta_name (delta_id, &from, &to, error))
|
||||
goto out;
|
||||
|
||||
superblock_path = _ostree_get_relative_static_delta_superblock_path (from, to);
|
||||
|
||||
if (!ot_util_variant_map_at (self->repo_dir_fd, superblock_path,
|
||||
|
||||
@@ -4701,7 +4701,9 @@ ostree_repo_regenerate_summary (OstreeRepo *self,
|
||||
glnx_fd_close int superblock_file_fd = -1;
|
||||
g_autoptr(GInputStream) in_stream = NULL;
|
||||
|
||||
_ostree_parse_delta_name (delta_names->pdata[i], &from, &to);
|
||||
if (!_ostree_parse_delta_name (delta_names->pdata[i], &from, &to, error))
|
||||
goto out;
|
||||
|
||||
superblock = _ostree_get_relative_static_delta_superblock_path ((from && from[0]) ? from : NULL, to);
|
||||
superblock_file_fd = openat (self->repo_dir_fd, superblock, O_RDONLY | O_CLOEXEC);
|
||||
if (superblock_file_fd == -1)
|
||||
|
||||
Reference in new issue
Block a user