The smatch error --------------
top.c +1414 calibrate_fields(78) error: buffer overflow 'Fieldstab' 39 <= 39
The code -----------------------
if (P_MAXPFLGS < f) { w->endpflg = i; continue; }
The background -----------------
The enum P_MAXPFLGS is strictly a fencepost and can *never* appear in
the arrays pflgsall or procflgs. Thus it (39th element) cannot be used
in referencing Fieldstab.
However, two enums of higher value (X_XON=40 and X_XOF=41) *can* appear
in those arrays. But the test against the fencepost ensures that those
two enums are *never* used in referencing Fieldstab.
When the analyzer sees the conditional using '<' and not '<='
it reports a false positive.
The source was changed to accommodate the tool's deficiency
With forest view mode under procps-ng-3.3.0, top would catch
a SEGV and exit. The problem was thought to be related to
some linux version 3 anamoly.
In procps-ng-3.3.1, top was protected from abnormal exit and
would display the offending processes with the special orphan
notation '?', instead of the usual artwork.
As it turns out, the problem wasn't with linux and could
surface under a 2.6.xx kernel, The cause was an occasional
abnormal ordering of tid/tgid/ppid which went unresolved
due to a progressive proc table scan in the recursive
function forest_add().
By default the proc table scan now restarts at the beginning.
However, a #define TREE_ONEPASS is provided should one wish
to restore the 3.3.1 behavior with its reduced overhead.
An anomaly would surface whenever the sort column was
made non-display under fields management.
The scroll message would report incorrect x coordinates
and the 'x' toggle would produce an unintentional
horizontal scroll.
This patch forces column highlighting off whenever field
changes are made (as is done for horizontal scrolling).
It also inactivates the 'x' toggle whenever the sort
column is not visible.
This bug has yet to be reported.
In the procs_refresh() function:
. the proctable scan was simplified
. memory allocation is now much more efficient
. window ppts will usually not now need xrealloc
Now that the library allows for customizing the response to
memory allocation errors, it is no longer necessary for top
to provide its own.
This library extension was necessary since top modifies the
termios structure and there would otherwise be no way to
restore the users tty.
tweaked signal setup valgrind complaint as nls
some input error messages made more descriptive
eliminated audible escape a from all error messa
added include of proc readproc.h to top.h
optimization for show_special function
remove unnecessary variables clang analyze
ps program
. etimes added for ELAPSED expressed in seconds
. time_t used in place of former unsigned long
top program
. corrected scroll message bug when 'x' toggle on
. fixed forest view potential missing libflags bug
. improved 'k' default signal invocation logic
. enhanced logic for %CPU maximums displayed
. made signal handling more robust and efficient
ps
. added tgid support
. made process/task naming consistent
top
. added tgid support
. standardized pid related width logic
documents
. added tgid to ps & top man documents
library
. fixed OOMEM_ENABLE readtask bug
. corrected header typo for tgid
Library changes
readproc
. added readeither to more efficiently
fill both process and thread proc_t
. added readproctab3, uses readeither
. included task path support in:
fill_cgroup_cvt, fill_cmdline_cvt,
read_unvectored
. QUICK_THREADS #define allows copying
process info vs. repeatedly reading
. simple_nexttid no longer values ppid
. path var made non-static in readtask
. documented 'proc_data_t' in .h file
. tweaked some c comments & formatting
library.map
. added new readeither, readproctab3
Program changes
ps
. exploits readproctab3 where possible
. improved args/comm compliance
top
. exploits readeither
Library changes
readproc
. added support for supplementary groups
. eliminated 2 potential mem leak sources
. shortcut used for multi-threaded str
vectors & ptrs was obsoleted
. freeing of proc_t related dynamic
memory now rests with the library
. standardized/normalized many c comments
sysinfo
. corrected note regarding glibc & cpuinfo
library.map
. made the visible freeproc accessable
Program changes
pmap
. initialized buffer for new readproc i/f
. eliminated now obsolete free() call
ps
. added width aware supgrp support
. initialized buffers for new readproc i/f
. eliminated now obsolete free() calls
top
. added supgrp support as variable width
. eliminated now obsolete free() calls
. expoilted library freeproc function
. corrected -h|v args text & spacing
. updated some c comments
Documentation changes
ps.1
. added supgid and supgrp
top.1
. added supgid and supgrp
. addition of above required renumbering
many fields in section 3a. DESCRIPTIONS
Program changes
. corrected eolcap handling if EQUCOLHDRYES defined
. added missing terminator for OOMEM_ENABLE comment
. tightened logic in display_fields
. eliminated some warnings via type or cast
. updated miscellaneous source comments
Man Document changes
. corrected/expanded CGROUPS narrative
. standardized/normalized PPID narrative
Signed-off-by: Jan Görig <jgorig@redhat.com>
This source patch addresses the following:
Enhancements
. added -w command line switch, with optional argument
( offers complete control over width and height, in )
( combination with env variables COLUMNS= and LINES= )
. updated man document to reflect the new capability
. reengineered Fields Management to be more flexible
thus no longer requiring a normal sized tty
Buglets fixed
. forced View_SCROLL off when in 'Batch' mode
. for narrow xterm, fixed return val in show_pmt
. for narrow xterm, fixed cursor pos in linein
. added a window specific end-of-line termcap ptr
( so clr_eol does not overwrite last printable char )
Cosmetic changes
. eliminated TTYGETENVYES define, incorporated as -w
. eliminated RESIZE_LIMIT define, no longer needed
. eliminated FIELD_CURSOR define, no longer possible
. eliminated extra text on Fields Management screen
. fixed miscellaneous man document typos/formatting
Signed-off-by: Jan Görig <jgorig@redhat.com>
Library Changes
. added PROC_EDITCMDLCVT flag
. added an internal (static) fill_cmdline_cvt function:
- reads and "escapes" /proc/#/cmdline
- returns result as a single string in a single vector
- callers are guaranteed a cmdline (no more NULL)
. added vectorize_this_str function, exploited by
fill_cgroup_cvt, fill_cmdline_cvt
. generalized read_cmdline function as read_unvectored, now
exploited by fill_cgroup_cvt, fill_cmdline_cvt, read_cmdline
( cgroup and cmdline no longer need be converted to string )
( vectors before being transformed to final representation )
. fixed bug regarding skipped group numbers (when enabled)
. escape_str made responsible for all single byte translation
with distinction between control chars + other unprintable
. added escaped_copy function for already escaped strings
. reorganized parts of proc_t to restore formatting standards
( displacement changes shouldn't matter with new version # )
. former ZAP_SUSEONLY #define now OOMEM_ENABLE
. added to library.map: escaped_copy; read_cmdline
Top Program Changes
. exploited the new PROC_EDITCMDLCVT provision
. eliminated now obsolete #include "proc/escape.h"
. changed the P_WCH display format if no kernel symbol table
. fixed very old bug in lflgs for out-of-view sort fields
. former ZAP_SUSEONLY #define now OOMEM_ENABLE
Ps Program Changes
. exploited the new PROC_EDITCMDLCVT provision
. exploited the new escaped_copy function
. consolidated pr_args and pr_comm into pr_argcom
Signed-off-by: Jan Görig <jgorig@redhat.com>
This source patchset addresses the following:
Library Extension (readproc)
. added PROC_EDITCGRPCVT flag
. added an internal (static) fill_cgroup_cvt function:
. reads AND parses /proc/#/cgroup
. returns result as a single string in a single vector
. thus no changes to proc_t structure or free memory logic
Program Enhancements (top)
. removed parse_cgroup logic in favor of libproc
. eliminated cgroup sort recurring overhead
. converted WCHAN field to variable width
. generalized variable width field logic in task_show
. real-time notation under P col more distinctive as 'rt'
Program Cosmetic (top)
. CGROUP now known as CGROUPS (plural)
. moved jan's attribution from top.c to 'Notes' in top.h
. numerous comments tweaked
Document Enhancements (top)
. documented CGROUPS field (required renumbering all fields)
. adapted narratives for the 3 current variable width fields
. expanded real-time scheduling notes, 'RT' now shown as 'rt'
Signed-off-by: Jan Görig <jgorig@redhat.com>
This source patch addresses the following:
Conceivable Buglets Avoided
. added sanity checks for previous assumptions re: pid size, num cpus
. changed response for rcfile errors to fatal, vs. silent default
Enhancements
. reorganized WIN_t struct for reduced padding and better readability
. generalized code for multiple var-width cols (divorced from pflags)
. absorbed jan gorig's cgroup patch, with attribution
Cosmetic
. reduced numerous #ifdef directives, especially in calibrate_fields
The documentation portion of the patch addresses the following:
README.top
. corrected a minor typo
. updated to reflect current patch level
top.1
. fixed potentially misinterpreted Me/ME strings
. added '.Bd -literal' directives for indented fixed-width font
. some comments changed from \# to .\" to avoid man2html problems
The source portion of the patch addresses the following:
Buglets
. header/task output length now consistent
. fixed 2 obscure horizontal scrolling bugs
. fixed potential bug regarding 'help' and 'current' window
. messages and prompts are now also sensitive to terminal width
. normalized buffer names/sizes now accommodate any SCREENMAX changes
Features
. made %CPU and 'i' mode handling more efficient
. for input the Up/Dn arrows keys act as alternatives to Ins/Del keys
. an optional USE_X_COLHDR define eliminates ALL 'x' toggle overhead
. an optional ZAP_SUSEONLY define was added for Werner's modifications
Cosmetic
. defines and format for optional end-of-job reports standardized