X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=lib%2Fcrypt_plain.c;h=3f8e96b7683e727e830f7b272d5e25c6e0821073;hb=ad21d48762fa70838d4ab4fbe8fe2a2e8a4dcef1;hp=61a93f5b3af814efcc6a285a2c2ea53bb0e188ae;hpb=d0b21614422d7ecd787aeffb894eba1a6973f4fa;p=platform%2Fupstream%2Fcryptsetup.git diff --git a/lib/crypt_plain.c b/lib/crypt_plain.c index 61a93f5..3f8e96b 100644 --- a/lib/crypt_plain.c +++ b/lib/crypt_plain.c @@ -1,7 +1,7 @@ /* * cryptsetup plain device helper functions * - * Copyright (C) 2004, Christophe Saout + * Copyright (C) 2004, Jana Saout * Copyright (C) 2010-2012 Red Hat, Inc. All rights reserved. * Copyright (C) 2010-2012, Milan Broz * @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include "libcryptsetup.h" @@ -83,7 +83,11 @@ int crypt_plain_hash(struct crypt_device *ctx __attribute__((unused)), /* hash[:hash_length] */ if ((s = strchr(hash_name_buf, ':'))) { *s = '\0'; - hash_size = atoi(++s); + s++; + if (!*s || sscanf(s, "%zd", &hash_size) != 1) { + log_dbg("Hash length is not a number"); + return -EINVAL; + } if (hash_size > key_size) { log_dbg("Hash length %zd > key length %zd", hash_size, key_size); @@ -95,7 +99,16 @@ int crypt_plain_hash(struct crypt_device *ctx __attribute__((unused)), pad_size = 0; } - r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase); + /* No hash, copy passphrase directly */ + if (!strcmp(hash_name_buf, "plain")) { + if (passphrase_size < hash_size) { + log_dbg("Too short plain passphrase."); + return -EINVAL; + } + memcpy(key, passphrase, hash_size); + r = 0; + } else + r = hash(hash_name_buf, hash_size, key, passphrase_size, passphrase); if (r == 0 && pad_size) memset(key + hash_size, 0, pad_size);