summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-10-25 12:57:07 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-10-25 14:06:41 +1000
commita41214bc9a0f326c6dc129e4a6382efb8b826862 (patch)
treebdef8ca2ac441e674cadabfd06ad457457bca981 /hw
parentffe20acedb3cdc4811eb52f8fc540ba6af7339fa (diff)
kdrive: check for null memory, fix OOB
If key/value allocation failed, don't bother adding another InputOption. And make sure the memory allocated is large enough for the trailing \0 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/kdrive/src/kinput.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index a1bbcaace..6a1ce49e0 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1049,10 +1049,15 @@ KdGetOptions (InputOption **options, char *string)
if (strchr(string, '='))
{
tam_key = (strchr(string, '=') - string);
- key = malloc(tam_key);
+ key = malloc(tam_key + 1);
+ if (!key)
+ goto out;
+
strncpy(key, string, tam_key);
key[tam_key] = '\0';
value = strdup(strchr(string, '=') + 1);
+ if (!value)
+ goto out;
}
else
{
@@ -1064,6 +1069,7 @@ KdGetOptions (InputOption **options, char *string)
if (newopt)
*options = newopt;
+out:
free(key);
free(value);