From 83794843b59c529ef8e637da4a0f91201806c49e Mon Sep 17 00:00:00 2001 From: Ales Ledvinka Date: Wed, 16 Jan 2013 12:33:13 +0000 Subject: [PATCH] 3600921 similar code as hpmfwupg reading negative length from failed ftell --- ipmitool/lib/ipmi_ime.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ipmitool/lib/ipmi_ime.c b/ipmitool/lib/ipmi_ime.c index d2102ec..b520ce5 100755 --- a/ipmitool/lib/ipmi_ime.c +++ b/ipmitool/lib/ipmi_ime.c @@ -90,6 +90,7 @@ #include #include +#include #include static const int IME_SUCCESS = 0; @@ -893,13 +894,21 @@ static int ImeImageCtxFromFile( /* Get the raw data in file */ fseek(pImageFile, 0, SEEK_END); pImageCtx->size = ftell(pImageFile); + if (pImageCtx->size <= 0) { + if (pImageCtx->size < 0) + lprintf(LOG_ERR, "Error seeking %s. %s\n", imageFilename, strerror(errno)); + rc = IME_ERROR; + fclose(pImageFile); + return rc; + } pImageCtx->pData = malloc(sizeof(unsigned char)*pImageCtx->size); rewind(pImageFile); if ( pImageCtx->pData != NULL ) { - fread(pImageCtx->pData, sizeof(unsigned char), - pImageCtx->size, pImageFile); + if (pImageCtx->size < fread(pImageCtx->pData, sizeof(unsigned char), + pImageCtx->size, pImageFile)) + rc = IME_ERROR; } else {