From: Jim Meyering Date: Wed, 10 Feb 2010 10:54:24 +0000 (+0100) Subject: absolutePathFromBaseFile: avoid an unnecessary use of assert X-Git-Tag: v0.7.7~210 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3042683bdebc3aa882d48d8bcab53cf870dc990;p=thirdparty%2Flibvirt.git absolutePathFromBaseFile: avoid an unnecessary use of assert * src/util/storage_file.c (absolutePathFromBaseFile): While this use of virAsprintf is slightly cleaner than using stpncpy(stpcpy(..., it does impose an artificial limitation on the length of the base_file name. Rather than asserting that it does not exceed INT_MAX, return NULL when it does. --- diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 3b69210e8c..f8e528d30e 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -26,7 +26,6 @@ #include #include -#include #include "dirname.h" #include "ignore-value.h" #include "memory.h" @@ -251,7 +250,8 @@ absolutePathFromBaseFile(const char *base_file, const char *path) return strdup(path); /* Ensure that the following cast-to-int is valid. */ - assert (d_len <= INT_MAX); + if (d_len > INT_MAX) + return NULL; ignore_value(virAsprintf(&res, "%.*s/%s", (int) d_len, base_file, path)); return res;