summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Mraz <tmraz@fedoraproject.org>2019-03-26 10:12:09 +0100
committerTomas Mraz <tmraz@fedoraproject.org>2019-03-26 10:12:09 +0100
commit9d6140b4c37f39cdd0c1947adf07dc5ca1762055 (patch)
tree1ca650e526baba053c07f04366b40ccab22ea4a9
parenta29312f21c2012c2bb0a67dd5558ad713b0fe12f (diff)
downloadlibpwquality-git-9d6140b4c37f39cdd0c1947adf07dc5ca1762055.tar.gz
Fix harmless one byte buffer underflow on read
When settings file has comments spanning a whole line there is harmless one byte read before the line buffer. Thanks Emiel Bruijntjes for finding the issue.
-rw-r--r--src/settings.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/settings.c b/src/settings.c
index 4f11537..922a55d 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -134,7 +134,8 @@ read_config_file(pwquality_settings_t *pwq, const char *cfgfile, void **auxerror
int eq;
len = strlen(linebuf);
- if (linebuf[len - 1] != '\n' && !feof(f)) {
+ /* len cannot be 0 unless there is a bug in fgets */
+ if (len && linebuf[len - 1] != '\n' && !feof(f)) {
(void) fclose(f);
return PWQ_ERROR_CFGFILE_MALFORMED;
}
@@ -146,13 +147,13 @@ read_config_file(pwquality_settings_t *pwq, const char *cfgfile, void **auxerror
}
/* drop terminating whitespace including the \n */
- do {
+ while (ptr > linebuf) {
if (!isspace(*(ptr-1))) {
*ptr = '\0';
break;
}
--ptr;
- } while (ptr > linebuf);
+ }
/* skip initial whitespace */
for (ptr = linebuf; isspace(*ptr); ptr++);