]> granicus.if.org Git - procps-ng/commitdiff
sysctl: Print lines longer than 1024 chars
authorWerner Fink <werner@suse.de>
Mon, 22 May 2017 12:31:34 +0000 (22:31 +1000)
committerCraig Small <csmall@enc.com.au>
Mon, 22 May 2017 12:31:34 +0000 (22:31 +1000)
as well do not open /proc/sys files if only the names of the
system control names of the kernel parameters should be shown.
Avoid leaking tmpname in case of a pattern mismatch.

Signed-off-by: Werner Fink <werner@suse.de>
sysctl.c

index c3072a1725f7eb8680664db22486c993b664ac27..29f31af6e9e027850dd7d771dc0e30c2825d95ee 100644 (file)
--- a/sysctl.c
+++ b/sysctl.c
@@ -209,8 +209,13 @@ static int ReadSetting(const char *restrict const name)
        }
 
        if (pattern && !pattern_match(outname, pattern)) {
-               free(outname);
-               return 0;
+               rc = 0;
+               goto out;
+       }
+
+       if (NameOnly) {
+               fprintf(stdout, "%s\n", outname);
+               goto out;
        }
 
        fp = fopen(tmpname, "r");
@@ -239,24 +244,25 @@ static int ReadSetting(const char *restrict const name)
                         * /sbin/sysctl -a | egrep -6 dev.cdrom.info
                         */
                        do {
-                               if (NameOnly) {
-                                       fprintf(stdout, "%s\n", outname);
-                               } else {
-                                       /* already has the \n in it */
-                                       if (PrintName) {
-                                               fprintf(stdout, "%s = %s",
-                                                       outname, inbuf);
-                                               if (inbuf[strlen(inbuf) - 1] != '\n')
-                                                       putchar('\n');
-                                       } else {
-                                               if (!PrintNewline) {
-                                                       char *nlptr =
-                                                           strchr(inbuf, '\n');
-                                                       if (nlptr)
-                                                               *nlptr = '\0';
-                                               }
+                               char *nlptr;
+                               if (PrintName) {
+                                       fprintf(stdout, "%s = ", outname);
+                                       do {
                                                fprintf(stdout, "%s", inbuf);
+                                               nlptr = &inbuf[strlen(inbuf) - 1];
+                                               /* already has the \n in it */
+                                               if (*nlptr == '\n')
+                                                       break;
+                                       } while (fgets(inbuf, sizeof inbuf - 1, fp));
+                                       if (*nlptr != '\n')
+                                               putchar('\n');
+                               } else {
+                                       if (!PrintNewline) {
+                                               nlptr = strchr(inbuf, '\n');
+                                               if (nlptr)
+                                                       *nlptr = '\0';
                                        }
+                                       fprintf(stdout, "%s", inbuf);
                                }
                        } while (fgets(inbuf, sizeof inbuf - 1, fp));
                } else {