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:
Jonathan Lebon authored and Atomic Bot committed 2016-09-09 19:06:11 +00:00
1 parent 36e8ba124e
commit 12e916466c
6 files changed
+77 -21

No files matched your search

+33 -9
View File
@@ -31,25 +31,49 @@ static void
test_ostree_parse_delta_name (void)
{
{
g_autofree char *from;
g_autofree char *to;
_ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d", &from, &to);
g_autofree char *from = NULL;
g_autofree char *to = NULL;
g_assert (_ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d", &from, &to, NULL));
g_assert_cmpstr (to, ==, "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d");
g_assert_null (from);
}
{
g_autofree char *from;
g_autofree char *to;
_ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d-5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03", &from, &to);
g_autofree char *from = NULL;
g_autofree char *to = NULL;
g_assert (_ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d-5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03", &from, &to, NULL));
g_assert_cmpstr (from, ==, "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d");
g_assert_cmpstr (to, ==, "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03");
}
{
g_autofree char *from;
g_autofree char *to;
_ostree_parse_delta_name ("", &from, &to);
g_autofree char *from = NULL;
g_autofree char *to = NULL;
g_assert (!_ostree_parse_delta_name ("", &from, &to, NULL));
g_assert_null (from);
g_assert_null (to);
}
{
g_autofree char *from = NULL;
g_autofree char *to = NULL;
g_assert (!_ostree_parse_delta_name ("GARBAGE", &from, &to, NULL));
g_assert_null (from);
g_assert_null (to);
}
{
g_autofree char *from = NULL;
g_autofree char *to = NULL;
g_assert (!_ostree_parse_delta_name ("GARBAGE-5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03", &from, &to, NULL));
g_assert_null (from);
g_assert_null (to);
}
{
g_autofree char *from = NULL;
g_autofree char *to = NULL;
g_assert (!_ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d-GARBAGE", &from, &to, NULL));
g_assert_null (from);
g_assert_null (to);
}
+8 -1
View File
@@ -26,7 +26,7 @@ skip_without_user_xattrs
bindatafiles="bash true ostree"
morebindatafiles="false ls"
echo '1..10'
echo '1..11'
mkdir repo
${CMD_PREFIX} ostree --repo=repo init --mode=archive-z2
@@ -235,3 +235,10 @@ ${CMD_PREFIX} ostree --repo=repo2 fsck
${CMD_PREFIX} ostree --repo=repo2 ls ${samerev} >/dev/null
echo 'ok pull empty delta part'
if ${CMD_PREFIX} ostree --repo=repo static-delta show GARBAGE 2> err.txt; then
assert_not_reached "static-delta show GARBAGE unexpectedly succeeded"
fi
assert_file_has_content err.txt "Invalid rev 'GARBAGE'"
echo 'ok handle bad delta name'