]> git.proxmox.com Git - mirror_qemu.git/commitdiff
crypto: add mode check in qcrypto_cipher_new() for cipher-builtin
authorGonglei <arei.gonglei@huawei.com>
Mon, 26 Sep 2016 09:23:23 +0000 (17:23 +0800)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 19 Oct 2016 09:09:24 +0000 (10:09 +0100)
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
crypto/cipher-builtin.c

index fd59a9e4618167e40260b35556f382afdc0b3369..b4bc2b9ca6bc0e969ca5384d1e8d1f0ef7afa96d 100644 (file)
@@ -433,6 +433,17 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
 {
     QCryptoCipher *cipher;
 
+    switch (mode) {
+    case QCRYPTO_CIPHER_MODE_ECB:
+    case QCRYPTO_CIPHER_MODE_CBC:
+    case QCRYPTO_CIPHER_MODE_XTS:
+        break;
+    default:
+        error_setg(errp, "Unsupported cipher mode %s",
+                   QCryptoCipherMode_lookup[mode]);
+        return NULL;
+    }
+
     cipher = g_new0(QCryptoCipher, 1);
     cipher->alg = alg;
     cipher->mode = mode;