summaryrefslogtreecommitdiff
path: root/quotaops.c
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2017-05-18 12:29:50 +0300
committerJan Kara <jack@suse.cz>2017-05-18 12:27:34 +0200
commita431ffcc27b364b7cc2b280ad33873e0157e7e99 (patch)
tree9d4ef2cdacba3874ddd587cd1ae1c2a1343eb833 /quotaops.c
parent9aa3a11857109297b521d0a8926dd90361b991ed (diff)
downloadlinuxquota-a431ffcc27b364b7cc2b280ad33873e0157e7e99.tar.gz
quotaops: check return code of fgets calls
fgets can return NULL anytime, do not ignore it. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'quotaops.c')
-rw-r--r--quotaops.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/quotaops.c b/quotaops.c
index 5e6026e..6f245b7 100644
--- a/quotaops.c
+++ b/quotaops.c
@@ -330,8 +330,12 @@ int readprivs(struct dquot *qlist, int infd)
/*
* Discard title lines, then read lines to process.
*/
- fgets(line, sizeof(line), fd);
- fgets(line, sizeof(line), fd);
+ if (!fgets(line, sizeof(line), fd) ||
+ !fgets(line, sizeof(line), fd)) {
+ errstr(_("Bad format: two title lines assumed\n"));
+ fclose(fd);
+ return -1;
+ }
while (fgets(line, sizeof(line), fd)) {
cnt = sscanf(line, "%s %s %s %s %s %s %s",
@@ -481,9 +485,13 @@ int readindividualtimes(struct dquot *qlist, int infd)
/*
* Discard title lines, then read lines to process.
*/
- fgets(line, sizeof(line), fd);
- fgets(line, sizeof(line), fd);
- fgets(line, sizeof(line), fd);
+ if (!fgets(line, sizeof(line), fd) ||
+ !fgets(line, sizeof(line), fd) ||
+ !fgets(line, sizeof(line), fd)) {
+ errstr(_("Bad format: three title lines assumed\n"));
+ fclose(fd);
+ return -1;
+ }
time(&now);
while (fgets(line, sizeof(line), fd)) {
@@ -583,9 +591,13 @@ int readtimes(struct quota_handle **handles, int infd)
/*
* Discard three title lines, then read lines to process.
*/
- fgets(line, sizeof(line), fd);
- fgets(line, sizeof(line), fd);
- fgets(line, sizeof(line), fd);
+ if (!fgets(line, sizeof(line), fd) ||
+ !fgets(line, sizeof(line), fd) ||
+ !fgets(line, sizeof(line), fd)) {
+ errstr(_("Bad format: three title lines assumed\n"));
+ fclose(fd);
+ return -1;
+ }
while (fgets(line, sizeof(line), fd)) {
cnt = sscanf(line, "%s %d %s %d %s", fsp, &btime, bunits, &itime, iunits);