Lines 23-28
Link Here
|
23 |
* |
23 |
* |
24 |
* Changelog: |
24 |
* Changelog: |
25 |
* Ighighi X - Improved speed via break command - 2005/03/27 |
25 |
* Ighighi X - Improved speed via break command - 2005/03/27 |
|
|
26 |
* Stewart Gebbie - fixed buffer overrun bug related to MAXREAD and UT_PIDLENGTH - 2007-10-20 |
26 |
* |
27 |
* |
27 |
*/ |
28 |
*/ |
28 |
|
29 |
|
Lines 42-48
Link Here
|
42 |
#endif |
43 |
#endif |
43 |
#include <ctype.h> |
44 |
#include <ctype.h> |
44 |
|
45 |
|
45 |
#define MAXREAD 1024 |
46 |
#define MAXREAD 4096 |
46 |
#define MAXBUF 4096 |
47 |
#define MAXBUF 4096 |
47 |
#define MAXLENGTH 256 |
48 |
#define MAXLENGTH 256 |
48 |
#define UT_PIDSIZE 12 |
49 |
#define UT_PIDSIZE 12 |
Lines 57-69
Link Here
|
57 |
#endif |
58 |
#endif |
58 |
|
59 |
|
59 |
struct ps_line { |
60 |
struct ps_line { |
60 |
char ps_tty[UT_LINESIZE]; |
61 |
char ps_tty[UT_LINESIZE+1]; |
61 |
char ps_user[UT_NAMESIZE]; |
62 |
char ps_user[UT_NAMESIZE+1]; |
62 |
char ps_args[MAXLENGTH]; |
63 |
char ps_args[MAXLENGTH+1]; |
63 |
int ps_pid; |
64 |
int ps_pid; |
64 |
}; |
65 |
}; |
65 |
struct utmp_line { |
66 |
struct utmp_line { |
66 |
char ut_tty[UT_LINESIZE]; |
67 |
char ut_tty[UT_LINESIZE+1]; |
67 |
int ut_pid; |
68 |
int ut_pid; |
68 |
int ut_type; |
69 |
int ut_type; |
69 |
}; |
70 |
}; |
Lines 77-83
Link Here
|
77 |
int fetchps(struct ps_line *psl_p) |
78 |
int fetchps(struct ps_line *psl_p) |
78 |
{ |
79 |
{ |
79 |
FILE *ps_fp; |
80 |
FILE *ps_fp; |
80 |
char line[MAXREAD + 1], pid[UT_PIDSIZE]; |
81 |
char line[MAXREAD + 1], pid[UT_PIDSIZE+1]; |
81 |
char *s, *d; |
82 |
char *s, *d; |
82 |
struct ps_line *curp = &psl_p[0]; |
83 |
struct ps_line *curp = &psl_p[0]; |
83 |
struct ps_line *endp = &psl_p[MAXBUF]; |
84 |
struct ps_line *endp = &psl_p[MAXBUF]; |
Lines 97-103
Link Here
|
97 |
while (isspace(*s)) /* skip spaces */ |
98 |
while (isspace(*s)) /* skip spaces */ |
98 |
s++; |
99 |
s++; |
99 |
d = pid; |
100 |
d = pid; |
100 |
for (x = 0; (!isspace(*s)) && (*d++ = *s++) && x <= UT_LINESIZE; x++) /* grab pid */ |
101 |
for (x = 0; (!isspace(*s)) && (*d++ = *s++) && x <= UT_PIDSIZE; x++) /* grab pid */ |
101 |
; |
102 |
; |
102 |
*d = '\0'; |
103 |
*d = '\0'; |
103 |
curp->ps_pid = atoi(pid); |
104 |
curp->ps_pid = atoi(pid); |