diff options
author | Dmitri Pal <dpal@redhat.com> | 2013-01-26 16:47:56 -0500 |
---|---|---|
committer | Ondrej Kos <okos@redhat.com> | 2013-01-28 10:47:33 +0100 |
commit | 059519fb2a8d056eba5f61cde98ed8b5292195d4 (patch) | |
tree | dc813f14b0ae1015bb700a36141e328044af2b92 | |
parent | 66e30c2f3862093505a8497744207d2812c95be3 (diff) | |
download | ding-libs2-059519fb2a8d056eba5f61cde98ed8b5292195d4.tar.gz ding-libs2-059519fb2a8d056eba5f61cde98ed8b5292195d4.tar.xz ding-libs2-059519fb2a8d056eba5f61cde98ed8b5292195d4.zip |
Check is the stats we collected
This patch corrects a problem related to stats being accessed
and evaluated without being initialized.
-rw-r--r-- | ini/ini_config_priv.h | 2 | ||||
-rw-r--r-- | ini/ini_fileobj.c | 13 | ||||
-rw-r--r-- | ini/ini_parse_ut.c | 30 |
3 files changed, 45 insertions, 0 deletions
diff --git a/ini/ini_config_priv.h b/ini/ini_config_priv.h index 31cee84..89ad8a9 100644 --- a/ini/ini_config_priv.h +++ b/ini/ini_config_priv.h @@ -69,6 +69,8 @@ struct ini_cfgfile { /**********************/ /* File stats */ struct stat file_stats; + /* Were stats read ? */ + int stats_read; }; /* Parsing error */ diff --git a/ini/ini_fileobj.c b/ini/ini_fileobj.c index 677383c..7d2011a 100644 --- a/ini/ini_fileobj.c +++ b/ini/ini_fileobj.c @@ -76,6 +76,8 @@ static int common_file_init(struct ini_cfgfile *file_ctx) return error; } + file_ctx->stats_read = 0; + /* Collect stats */ if (file_ctx->metadata_flags & INI_META_STATS) { errno = 0; @@ -85,6 +87,7 @@ static int common_file_init(struct ini_cfgfile *file_ctx) TRACE_ERROR_NUMBER("Failed to get file stats.", error); return error; } + file_ctx->stats_read = 1; } else memset(&(file_ctx->file_stats), 0, sizeof(struct stat)); @@ -231,7 +234,11 @@ int ini_config_access_check(struct ini_cfgfile *file_ctx, if ((file_ctx == NULL) || (flags == 0)) { TRACE_ERROR_NUMBER("Invalid parameter.", EINVAL); return EINVAL; + } + if (file_ctx->stats_read == 0) { + TRACE_ERROR_NUMBER("Stats were not collected.", EINVAL); + return EINVAL; } /* Check mode */ @@ -304,6 +311,12 @@ int ini_config_changed(struct ini_cfgfile *file_ctx1, return EINVAL; } + if ((file_ctx1->stats_read == 0) || + (file_ctx2->stats_read == 0)) { + TRACE_ERROR_NUMBER("Stats were not collected.", EINVAL); + return EINVAL; + } + *changed = 0; /* Unfortunately the time is not granular enough diff --git a/ini/ini_parse_ut.c b/ini/ini_parse_ut.c index 002fdd5..c5e9166 100644 --- a/ini/ini_parse_ut.c +++ b/ini/ini_parse_ut.c @@ -1085,6 +1085,36 @@ int startup_test(void) return error; } + /* Open config file not collecting stats */ + error = ini_config_file_open(outfile, + 0, + &file_ctx); + if (error) { + printf("Failed to open file %s for reading. Error %d.\n", + outfile, error); + return error; + } + + /* We will check just permissions here. */ + error = ini_config_access_check(file_ctx, + INI_ACCESS_CHECK_MODE, /* add uid & gui flags + * in real case + */ + 0, /* <- will be real uid in real case */ + 0, /* <- will be real gid in real case */ + 0440, /* Checking for r--r----- */ + 0); + /* This check is expected to fail since + * we did not collect stats + */ + ini_config_file_destroy(file_ctx); + + if (!error) { + printf("Expected error got success!\n"); + return EACCES; + } + + /* Open config file */ error = ini_config_file_open(outfile, INI_META_STATS, |