Commit 39b2b115 authored by Richard Bayerle's avatar Richard Bayerle
Browse files

Rewrite fingerprint generation

And fix wrong length check along the way
parent ca7087e8
......@@ -129,23 +129,25 @@ char * lurch_util_uname_get_db_fn(const char * uname, const char * which) {
char * lurch_util_fp_get_printable(const char * fp) {
char ** split = (void *) 0;
char * temp1 = (void *) 0;
char * temp2 = (void *) 0;
const size_t split_len = 32;
char * printable = (void *) 0;
const size_t printable_len = 72;
if (!fp || strlen(fp) != 95) {
if (!fp || strlen(fp) != 98) {
return (void *) 0;
}
split = g_strsplit(fp, ":", 0);
temp2 = g_strdup("");
printable = g_malloc0(printable_len);
for (int i = 1; i <= 32; i += 4) {
temp1 = g_strconcat(temp2, split[i], split[i+1], split[i+2], split[i+3], " ", NULL);
g_free(temp2);
temp2 = g_strdup(temp1);
g_free(temp1);
for (int i = 1; i <= split_len; i++) {
g_strlcat(printable, split[i], printable_len);
if (i % 4 == 0 && i != split_len) {
g_strlcat(printable, " ", printable_len);
}
}
g_strfreev(split);
return temp2;
return printable;
}
\ No newline at end of file
......@@ -163,11 +163,11 @@ static void test_lurch_util_fp_get_printable(void ** state) {
(void) state;
const char * fp_as_returned_by_pidgin =
"12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:ab:cd:ef";
"12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:ab:cd:ef:gh";
char * printable_fp = lurch_util_fp_get_printable(fp_as_returned_by_pidgin);
assert_non_null(printable_fp);
assert_string_equal(printable_fp, "34567812 34567812 34567812 34567812 34567812 34567812 34567812 abcdef");
assert_string_equal(printable_fp, "34567812 34567812 34567812 34567812 34567812 34567812 34567812 abcdefgh");
}
......@@ -177,9 +177,9 @@ static void test_lurch_util_fp_get_printable_invalid(void ** state) {
assert_null(lurch_util_fp_get_printable(NULL));
const char * too_short =
"12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:ab:cdef";
"12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:ab:cd:efgh";
const char * too_long =
"12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:ab:cd:ef:";
"12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:34:56:78:12:ab:cd:ef:gh:";
assert_null(lurch_util_fp_get_printable(too_short));
assert_null(lurch_util_fp_get_printable(too_long));
......
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