]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Suppress hardcoded table sizes 3090/head
authorRachid Koucha <47061324+Rachid-Koucha@users.noreply.github.com>
Thu, 11 Jul 2019 08:01:36 +0000 (10:01 +0200)
committerGitHub <noreply@github.com>
Thu, 11 Jul 2019 08:01:36 +0000 (10:01 +0200)
. Use sizeof() instead of hardcoded values
. snprintf(..., size, ""...) is in error if the return code is >= size (not sufficient to set only ">")

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
src/lxc/utils.c

index 6d8a65818a35d5fa3f08b37472352f36163bdf5a..bf4a9c2cbda4ea3a71e59685b1322bfce1bf5de2 100644 (file)
@@ -1171,8 +1171,8 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
                if (srcfd < 0)
                        return srcfd;
 
-               ret = snprintf(srcbuf, 50, "/proc/self/fd/%d", srcfd);
-               if (ret < 0 || ret > 50) {
+               ret = snprintf(srcbuf, sizeof(srcbuf), "/proc/self/fd/%d", srcfd);
+               if (ret < 0 || ret >= (int)sizeof(srcbuf)) {
                        close(srcfd);
                        ERROR("Out of memory");
                        return -EINVAL;
@@ -1191,8 +1191,8 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
                return destfd;
        }
 
-       ret = snprintf(destbuf, 50, "/proc/self/fd/%d", destfd);
-       if (ret < 0 || ret > 50) {
+       ret = snprintf(destbuf, sizeof(destbuf), "/proc/self/fd/%d", destfd);
+       if (ret < 0 || ret >= (int)sizeof(destbuf)) {
                if (srcfd != -1)
                        close(srcfd);