]> git.michaelhowe.org Git - packages/o/openafs.git/commit
dumptool: Remove newlines safely
authorSimon Wilkinson <sxw@your-file-system.com>
Thu, 28 Feb 2013 12:15:29 +0000 (12:15 +0000)
committerStephan Wiesand <stephan.wiesand@desy.de>
Tue, 3 Jun 2014 16:26:50 +0000 (12:26 -0400)
commit564573da48f61e5d96d5df017d25a39c930d566f
tree9120443ec4c536b53aa8e7c2815826c076d87d46
parent113ede2a6b43551efe9df19774202e91730dfe11
dumptool: Remove newlines safely

The code currently does

   fgets(cmdbuf, ... );
   cmdbuf[strlen(cmdbuf - 1)] = '\0';

in order to remove new lines from cmdbuf. Coverity thinks there's
a danger of strlen(cmdbuf) being 0, and thus the strlen being negative.
That shouldn't happen, but if fgets hits EOF midway through a line, we
might get a string that doesn't have a trailing '\n', and end up
removing the wrong character. Tidy this up by checking that the string
isn't 0 length, and that the character we're zapping is a newline.

Caught by coverity (#985430)

Reviewed-on: http://gerrit.openafs.org/9310
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
(cherry picked from commit 8f51502e5f45a43fba130d260813716be894d51e)

Change-Id: Ie165c8e50c4071c07fffa220601c8b5e92ccf815
Reviewed-on: http://gerrit.openafs.org/11026
Reviewed-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
src/tests/dumptool.c