9fc0f6
From cfb20c251cb79820ddf7507f9f4a54cc3f18b121 Mon Sep 17 00:00:00 2001
9fc0f6
From: Lennart Poettering <lennart@poettering.net>
9fc0f6
Date: Wed, 2 Oct 2013 19:36:28 +0200
9fc0f6
Subject: [PATCH] cryptsetup: fix OOM handling when parsing mount options
9fc0f6
9fc0f6
---
9fc0f6
 src/cryptsetup/cryptsetup.c | 11 ++++++-----
9fc0f6
 1 file changed, 6 insertions(+), 5 deletions(-)
9fc0f6
9fc0f6
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
9fc0f6
index 22b5eea..769c3e4 100644
9fc0f6
--- a/src/cryptsetup/cryptsetup.c
9fc0f6
+++ b/src/cryptsetup/cryptsetup.c
9fc0f6
@@ -74,7 +74,7 @@ static int parse_one_option(const char *option) {
9fc0f6
 
9fc0f6
                 t = strdup(option+7);
9fc0f6
                 if (!t)
9fc0f6
-                        return -ENOMEM;
9fc0f6
+                        return log_oom();
9fc0f6
 
9fc0f6
                 free(opt_cipher);
9fc0f6
                 opt_cipher = t;
9fc0f6
@@ -89,9 +89,10 @@ static int parse_one_option(const char *option) {
9fc0f6
         } else if (startswith(option, "tcrypt-keyfile=")) {
9fc0f6
 
9fc0f6
                 opt_type = CRYPT_TCRYPT;
9fc0f6
-                if (path_is_absolute(option+15))
9fc0f6
-                        opt_tcrypt_keyfiles = strv_append(opt_tcrypt_keyfiles, strdup(option+15));
9fc0f6
-                else
9fc0f6
+                if (path_is_absolute(option+15)) {
9fc0f6
+                        if (strv_extend(&opt_tcrypt_keyfiles, option + 15) < 0)
9fc0f6
+                                return log_oom();
9fc0f6
+                } else
9fc0f6
                         log_error("Key file path '%s' is not absolute. Ignoring.", option+15);
9fc0f6
 
9fc0f6
         } else if (startswith(option, "keyfile-size=")) {
9fc0f6
@@ -113,7 +114,7 @@ static int parse_one_option(const char *option) {
9fc0f6
 
9fc0f6
                 t = strdup(option+5);
9fc0f6
                 if (!t)
9fc0f6
-                        return -ENOMEM;
9fc0f6
+                        return log_oom();
9fc0f6
 
9fc0f6
                 free(opt_hash);
9fc0f6
                 opt_hash = t;