summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2008-11-03 18:19:02 -0800
committerShawn O. Pearce <spearce@spearce.org>2008-11-03 18:43:04 -0800
commit367ab010d69ec4fff533c770eba5b1882f79cb41 (patch)
tree7b5d9df4c3cff229a132e5684f5e5e7bf6219463
parentb81dd80e8cb77046b6196a1dec3f8f356307fcfb (diff)
downloadlibgit2-367ab010d69ec4fff533c770eba5b1882f79cb41.tar.gz
Add an extra oid test to verify control characters aren't read
We only want hex digits to be read, any other character in the 8-bit character set is invalid within an id string. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--tests/t0000-oid.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/t0000-oid.c b/tests/t0000-oid.c
index b0a3077f9..25263fda4 100644
--- a/tests/t0000-oid.c
+++ b/tests/t0000-oid.c
@@ -11,6 +11,43 @@ BEGIN_TEST(invalid_string_moo)
must_fail(git_oid_mkstr(&out, "moo"));
END_TEST
+static int from_hex(unsigned char i)
+{
+ if (i >= '0' && i <= '9')
+ return i - '0';
+ if (i >= 'a' && i <= 'f')
+ return 10 + (i - 'a');
+ if (i >= 'A' && i <= 'F')
+ return 10 + (i - 'A');
+ return -1;
+}
+
+BEGIN_TEST(invalid_string_all_chars)
+ git_oid out;
+ unsigned char exp[] = {
+ 0x16, 0xa6, 0x77, 0x70, 0xb7,
+ 0xd8, 0xd7, 0x23, 0x17, 0xc4,
+ 0xb7, 0x75, 0x21, 0x3c, 0x23,
+ 0xa8, 0xbd, 0x74, 0xf5, 0xe0,
+ };
+ char in[41] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0\0";
+ unsigned int i;
+
+ for (i = 0; i < 256; i++) {
+ in[38] = (char)i;
+
+ if (from_hex(i) >= 0) {
+ exp[19] = (from_hex(i) << 4);
+ if (git_oid_mkstr(&out, in))
+ test_die("line %d: must accept '%s'", __LINE__, in);
+ if (memcmp(out.id, exp, sizeof(out.id)))
+ test_die("line %d: bad parse of '%s', %x != %x",
+ __LINE__, in, exp[19], out.id[19]);
+ } else if (!git_oid_mkstr(&out, in))
+ test_die("line %d: must not accept '%s'", __LINE__, in);
+ }
+END_TEST
+
BEGIN_TEST(invalid_string_16a67770b7d8d72317c4b775213c23a8bd74f5ez)
git_oid out;
must_fail(git_oid_mkstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5ez"));