File chkrootkit-utmpchk.patch of Package chkrootkit

diff -urN chkrootkit-0.53.orig/chkutmp.c chkrootkit-0.53/chkutmp.c
--- chkrootkit-0.53.orig/chkutmp.c	2017-06-07 15:16:49.000000000 +0300
+++ chkrootkit-0.53/chkutmp.c	2019-04-23 11:35:55.766263644 +0300
@@ -44,7 +44,6 @@
 #endif
 #include <ctype.h>
 
-#define MAXREAD 1024
 #define MAXBUF 4096
 #define MAXLENGTH 256
 #define UT_PIDSIZE 12
@@ -59,13 +58,13 @@
 #endif
 
 struct ps_line {
-    char ps_tty[UT_LINESIZE];
-    char ps_user[UT_NAMESIZE];
-    char ps_args[MAXLENGTH];
+    char ps_tty[UT_LINESIZE+2];
+    char ps_user[UT_NAMESIZE+2];
+    char ps_args[MAXLENGTH+2];
     int ps_pid;
 };
 struct utmp_line {
-    char ut_tty[UT_LINESIZE];
+    char ut_tty[UT_LINESIZE+2];
     int ut_pid;
     int ut_type;
 };
@@ -79,7 +78,9 @@
 int fetchps(struct ps_line *psl_p)
 {
     FILE *ps_fp;
-    char line[MAXREAD + 1], pid[UT_PIDSIZE];
+    char *line = NULL;
+    size_t linelen = 0;
+    char pid[UT_PIDSIZE+2];
     char *s, *d;
     struct ps_line *curp = &psl_p[0];
     struct ps_line *endp = &psl_p[MAXBUF-1];
@@ -87,8 +88,8 @@
 
     i = 0;
     if ((ps_fp = (popen(cmd[PS_CMD], "r"))) != NULL) {
-	fgets(line, MAXREAD, ps_fp);	/* skip header */
-	while (fgets(line, MAXREAD, ps_fp)) {
+	getline(&line, &linelen, ps_fp);	/* skip header */
+	while (getline(&line, &linelen, ps_fp) != -1) {
 	    s = line;
 	    if (*s != '\?' && curp <= endp) {	/* only interested in lines that
 						 * have a tty */
@@ -99,7 +100,7 @@
 		while (isspace(*s))	/* skip spaces */
 		    s++;
 		d = pid;
-		for (x = 0; (!isspace(*s)) && (*d++ = *s++) && x <= UT_LINESIZE; x++)	/* grab pid */
+		for (x = 0; (!isspace(*s)) && (*d++ = *s++) && x <= UT_PIDSIZE; x++)	/* grab pid */
 		    ;
 		*d = '\0';
 		curp->ps_pid = atoi(pid);
@@ -114,17 +115,19 @@
 		    s++;
 		for (x = 0; (*d++ = *s++) && x <= MAXLENGTH; x++)	/* cmd + args */
 		    ;
+        *d = '\0';
 		i++;
 		curp++;
                 /* if we didn't read the line, skip the rest */ 
                 line_length = strlen(line); 
                 while (!(line_length == 0 || line[line_length -1] == '\n')) { 
-                   fgets(line, MAXREAD, ps_fp);
+                   fgets(line, 1024, ps_fp);
                    line_length = strlen(line); 
                 } 
 	    }
 	}
 	pclose(ps_fp);
+    free(line);
     } else {
 	fprintf(stderr, "\nfailed running 'ps' !\n");
 	exit(EXIT_FAILURE);
openSUSE Build Service is sponsored by