END_TEST START_TEST(test_utf8_check) { const char *invalid = "ad\351la\357d"; const uint8_t valid[] = { 'M', 0xC3, 0x9C, 'N', 'C', 'H', 'E', 'N', 0x0 }; bool ret; ret = sss_utf8_check(valid, strlen((const char *) valid)); fail_unless(ret == true, "Positive test failed\n"); ret = sss_utf8_check((const uint8_t *) invalid, strlen(invalid)); fail_unless(ret == false, "Negative test succeeded\n"); }
static int sbus_request_valist_check(va_list va, int first_arg_type) { int ret = EOK; #ifdef HAVE_DBUSBASICVALUE int type; va_list va_check; const DBusBasicValue *value; bool ok; va_copy(va_check, va); type = first_arg_type; while (type != DBUS_TYPE_INVALID) { value = va_arg(va_check, const DBusBasicValue*); if (type == DBUS_TYPE_STRING) { ok = sss_utf8_check((const uint8_t *) value->str, strlen(value->str)); if (!ok) { DEBUG(SSSDBG_MINOR_FAILURE, "sbus message argument [%s] contains invalid " "non-UTF8 characters\n", value->str); ret = EINVAL; break; } } type = va_arg(va_check, int); } va_end(va_check); #endif /* HAVE_DBUSBASICVALUE */ return ret; }
static int extract_string(char **var, size_t size, uint8_t *body, size_t blen, size_t *c) { uint8_t *str; if (*c+size > blen || SIZE_T_OVERFLOW(*c, size)) return EINVAL; str = body+(*c); if (str[size-1]!='\0') return EINVAL; /* If the string isn't valid UTF-8, fail */ if (!sss_utf8_check(str, size-1)) { return EINVAL; } *c += size; *var = (char *) str; return EOK; }