prevent CNAME/PTR parsing from reading data past the response end
[musl] / src / stdio / fgets.c
index 6171f39..4a100b3 100644 (file)
@@ -12,13 +12,14 @@ char *fgets(char *restrict s, int n, FILE *restrict f)
 
        FLOCK(f);
 
-       if (n--<=1) {
+       if (n<=1) {
                f->mode |= f->mode-1;
                FUNLOCK(f);
-               if (n) return 0;
+               if (n<1) return 0;
                *s = 0;
                return s;
        }
+       n--;
 
        while (n) {
                if (f->rpos != f->rend) {