Skip to content
Browse files

fix several API-detected bugs

  • Loading branch information...
1 parent f0318e7 commit 18ab2a2c07342f46a9fbb632d3e56d39bc9d64a1 @bwalex committed Jul 9, 2011
Showing with 32 additions and 16 deletions.
  1. +29 −15 tcplay.c
  2. +3 −1 tcplay_api.c
View
44 tcplay.c
@@ -950,13 +950,24 @@ check_cipher(const char *cipher, int quiet)
struct tc_cipher_chain *
check_cipher_chain(char *cipher_chain, int quiet)
{
- int i,k, found = 0, nciphers = 0, mismatch = 0;
+ struct tc_cipher_chain *cipher = NULL;
+ int i,k, nciphers = 0, mismatch = 0;
char *ciphers[8];
+ char *tmp_chain, *tmp_chain_free;
char *token;
- while ((token = strsep(&cipher_chain, ",")) != NULL)
+ if ((tmp_chain = strdup(cipher_chain)) == NULL) {
+ tc_log(1, "Could not allocate strdup memory\n");
+ return NULL;
+ }
+
+ tmp_chain_free = tmp_chain;
+
+ while ((token = strsep(&tmp_chain, ",")) != NULL)
ciphers[nciphers++] = token;
+ cipher = NULL;
+
for (i = 0; valid_cipher_chains[i][0] != NULL; i++) {
mismatch = 0;
@@ -979,27 +990,30 @@ check_cipher_chain(char *cipher_chain, int quiet)
* then we found the right cipher chain.
*/
if ((k == nciphers) && !mismatch) {
- found = 1;
+ cipher = tc_cipher_chains[i];
break;
}
}
- if (!found && !quiet) {
- fprintf(stderr, "Valid cipher chains are:\n");
- for (i = 0; valid_cipher_chains[i][0] != NULL; i++) {
- for (k = 0; valid_cipher_chains[i][k] != NULL; k++) {
- fprintf(stderr, "%s%c",
- valid_cipher_chains[i][k],
- (valid_cipher_chains[i][k+1] != NULL) ?
- ',' : '\0');
+ if (cipher == NULL) {
+ tc_log(1, "Invalid cipher: %s\n", cipher_chain);
+ if (!quiet) {
+ fprintf(stderr, "Valid cipher chains are:\n");
+ for (i = 0; valid_cipher_chains[i][0] != NULL; i++) {
+ for (k = 0; valid_cipher_chains[i][k] != NULL;
+ k++) {
+ fprintf(stderr, "%s%c",
+ valid_cipher_chains[i][k],
+ (valid_cipher_chains[i][k+1] != NULL) ?
+ ',' : '\0');
+ }
+ fprintf(stderr, "\n");
}
- fprintf(stderr, "\n");
}
-
- return NULL;
}
- return tc_cipher_chains[i];
+ free(tmp_chain_free);
+ return cipher;
}
struct pbkdf_prf_algo *
View
4 tcplay_api.c
@@ -57,7 +57,7 @@ tc_api_uninit(void)
const char *
tc_api_get_error_msg(void)
{
- return (tc_internal_verbose) ? "" : tc_internal_log_buffer;
+ return tc_internal_log_buffer;
}
const char *
@@ -91,6 +91,7 @@ tc_api_create_volume(tc_api_opts *api_opts)
return TC_ERR;
for (nkeyfiles = 0; (nkeyfiles < MAX_KEYFILES) &&
+ (api_opts->tc_keyfiles != NULL) &&
(api_opts->tc_keyfiles[nkeyfiles] != NULL); nkeyfiles++)
;
@@ -99,6 +100,7 @@ tc_api_create_volume(tc_api_opts *api_opts)
if (api_opts->tc_size_hidden_in_blocks > 0) {
create_hidden = 1;
for (n_hkeyfiles = 0; (n_hkeyfiles < MAX_KEYFILES) &&
+ (api_opts->tc_keyfiles_hidden != NULL) &&
(api_opts->tc_keyfiles_hidden[n_hkeyfiles] != NULL);
n_hkeyfiles++)
;

0 comments on commit 18ab2a2

Please sign in to comment.
Something went wrong with that request. Please try again.