static int split_otp(const char *otp, char **user, char **s_otp)
{
size_t otp_len, i, j;
+ int r;
/* Modhex doubles the length of the string, so grab the last
* YUBIKEY_BLOCK_SIZE * 2 octets to get the actual OTP */
otp_len = strlen(otp);
assert(otp_len > YUBIKEY_BLOCK_SIZE * 2);
assert(yubikey_modhex_p(otp));
- /* XXX error checking */
i = otp_len - YUBIKEY_BLOCK_SIZE * 2;
*user = malloc(i+1);
+ if (*user == NULL) {
+ return -1;
+ }
memcpy(*user, otp, i);
(*user)[i] = '\0';
j = YUBIKEY_BLOCK_SIZE * 2;
*s_otp = malloc(j+1);
+ if (*s_otp == NULL) {
+ free(*user);
+ return -1;
+ }
memcpy(*s_otp, otp + i, j);
(*s_otp)[j] = '\0';
+
return 0;
}