Fix missing headers
[platform/upstream/cryptsetup.git] / lib / utils_devpath.c
index 9472873..fc5175c 100644 (file)
@@ -4,10 +4,12 @@
  * Copyright (C) 2004, Christophe Saout <christophe@saout.de>
  * Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
  * Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2009-2012, Milan Broz
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,6 +28,7 @@
 #include <dirent.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <limits.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include "utils_dm.h"
@@ -134,7 +137,7 @@ char *crypt_lookup_dev(const char *dev_id)
        if (snprintf(path, sizeof(path), "/sys/dev/block/%s", dev_id) < 0)
                return NULL;
 
-       len = readlink(path, link, sizeof(link));
+       len = readlink(path, link, sizeof(link) - 1);
        if (len < 0) {
                /* Without /sys use old scan */
                if (stat("/sys/dev/block", &st) < 0)