main - cov: ignore syscall
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=efaab93491751ccf391...
Commit: efaab93491751ccf39108d076745c6774b263232
Parent: 055406bb398ddf60f18c545baffcec4ee4d5646e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 01:45:55 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: ignore syscall
---
daemons/lvmlockd/lvmlockd-core.c | 6 +++---
lib/device/bcache.c | 2 +-
test/lib/brick-shelltest.h | 36 ++++++++++++++++++------------------
test/lib/not.c | 2 +-
test/unit/activation-generator_t.c | 4 ++--
test/unit/percent_t.c | 26 +++++++++++++-------------
6 files changed, 38 insertions(+), 38 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index 701372220..c1785a764 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -919,7 +919,7 @@ static void write_adopt_file(void)
pthread_mutex_unlock(&lockspaces_mutex);
fflush(fp);
- fclose(fp);
+ (void) fclose(fp);
}
static int read_adopt_file(struct list_head *vg_lockd)
@@ -1010,11 +1010,11 @@ static int read_adopt_file(struct list_head *vg_lockd)
}
}
- fclose(fp);
+ (void) fclose(fp);
return 0;
fail:
- fclose(fp);
+ (void) fclose(fp);
return -1;
}
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index be25cc7e2..790ff71d3 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -734,7 +734,7 @@ static void _block_remove(struct block *b)
k.parts.di = b->di;
k.parts.b = b->index;
- radix_tree_remove(b->cache->rtree, k.bytes, k.bytes + sizeof(k.bytes));
+ (void) radix_tree_remove(b->cache->rtree, k.bytes, k.bytes + sizeof(k.bytes));
}
//----------------------------------------------------------------
diff --git a/test/lib/brick-shelltest.h b/test/lib/brick-shelltest.h
index 6bc02e0d2..517c0f7d9 100644
--- a/test/lib/brick-shelltest.h
+++ b/test/lib/brick-shelltest.h
@@ -102,7 +102,7 @@ struct dir {
if ( !d )
throw syserr( "error opening directory", p );
}
- ~dir() { closedir( d ); }
+ ~dir() { (void) closedir( d ); }
};
typedef std::vector< std::string > Listing;
@@ -111,8 +111,8 @@ inline void fsync_name( std::string n )
{
int fd = open( n.c_str(), O_WRONLY );
if ( fd >= 0 ) {
- fsync( fd );
- close( fd );
+ (void) fsync( fd );
+ (void) close( fd );
}
}
@@ -464,8 +464,8 @@ struct FileSink : FdSink {
~FileSink() {
if ( fd >= 0 ) {
- fsync( fd );
- close( fd );
+ (void) fsync( fd );
+ (void) close( fd );
}
}
};
@@ -515,7 +515,7 @@ struct Source {
Source( int _fd = -1 ) : fd( _fd ) {}
virtual ~Source() {
if ( fd >= 0 )
- ::close( fd );
+ (void) ::close( fd );
}
};
@@ -570,7 +570,7 @@ struct KMsg : Source {
can_clear = false;
} else if ( lseek( fd, 0L, SEEK_END ) == (off_t) -1 ) {
fprintf( stderr, "lseek log %s %s\n", read_msg, strerror( errno ) );
- close(fd);
+ (void) close(fd);
fd = -1;
}
#endif
@@ -712,13 +712,13 @@ struct TestProcess
if ( !interactive ) {
int devnull = ::open( "/dev/null", O_RDONLY );
if ( devnull >= 0 ) { /* gcc really doesn't like to not have stdin */
- dup2( devnull, STDIN_FILENO );
- close( devnull );
+ (void) dup2( devnull, STDIN_FILENO );
+ (void) close( devnull );
} else
- close( STDIN_FILENO );
- dup2( fd, STDOUT_FILENO );
- dup2( fd, STDERR_FILENO );
- close( fd );
+ (void) close( STDIN_FILENO );
+ (void) dup2( fd, STDOUT_FILENO );
+ (void) dup2( fd, STDERR_FILENO );
+ (void) close( fd );
}
setpgid( 0, 0 );
@@ -804,7 +804,7 @@ struct TestCase {
if ( waitpid( pid, &status, WNOHANG ) == 0 ) {
system( "echo t > /proc/sysrq-trigger 2> /dev/null" );
kill( -pid, SIGKILL );
- waitpid( pid, &status, 0 );
+ (void) waitpid( pid, &status, 0 );
}
timeout = true;
io.sync( true );
@@ -897,7 +897,7 @@ struct TestCase {
void parent()
{
- ::close( child.fd );
+ (void) ::close( child.fd );
setupIO();
journal->started( id() );
@@ -957,9 +957,9 @@ struct TestCase {
exit(201);
} else if (pid == 0) {
io.close();
- chdir( options.workdir.c_str() );
+ (void) chdir( options.workdir.c_str() );
if ( !options.flavour_envvar.empty() )
- setenv( options.flavour_envvar.c_str(), flavour.c_str(), 1 );
+ (void) setenv( options.flavour_envvar.c_str(), flavour.c_str(), 1 );
child.exec();
} else {
parent();
@@ -1053,7 +1053,7 @@ struct Main {
if ( options.cont )
journal.read();
else
- ::unlink( journal.location.c_str() );
+ (void) ::unlink( journal.location.c_str() );
}
int run() {
diff --git a/test/lib/not.c b/test/lib/not.c
index 0cff13062..0245c3475 100644
--- a/test/lib/not.c
+++ b/test/lib/not.c
@@ -80,7 +80,7 @@ int main(int args, char **argv) {
val = "5";
if (val)
- setenv("LVM_EXPECTED_EXIT_STATUS", val, 1);
+ (void) setenv("LVM_EXPECTED_EXIT_STATUS", val, 1);
execvp(argv[1], &argv[1]);
/* should not be accessible */
diff --git a/test/unit/activation-generator_t.c b/test/unit/activation-generator_t.c
index 7a2aa337b..f1e2aeda4 100644
--- a/test/unit/activation-generator_t.c
+++ b/test/unit/activation-generator_t.c
@@ -185,7 +185,7 @@ static const char *_fake_lvmconfig(const char *output)
fprintf(fp, "%s", output);
fprintf(fp, "EOF\n");
- fclose(fp);
+ (void) fclose(fp);
if (chmod(path, 0770))
test_fail("chmod 0777 failed on path %s", path);
@@ -234,7 +234,7 @@ static void _test_get_config(void *fixture)
test_fail("_get_config() <- '%s' unexpectedly succeeded", t->output);
}
- unlink(path);
+ (void) unlink(path);
}
}
diff --git a/test/unit/percent_t.c b/test/unit/percent_t.c
index 9b349a97c..3575e12b3 100644
--- a/test/unit/percent_t.c
+++ b/test/unit/percent_t.c
@@ -31,25 +31,25 @@ static void test_percent_100(void *fixture)
T_ASSERT_EQUAL(p1_100, DM_PERCENT_100);
T_ASSERT_NOT_EQUAL(n_100, DM_PERCENT_100);
- dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(p_100));
+ (void) dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(p_100));
T_ASSERT_EQUAL(strcmp(buf, "100.00"), 0);
- dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(p1_100));
+ (void) dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(p1_100));
T_ASSERT_EQUAL(strcmp(buf, "100.00"), 0);
- dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(n_100));
+ (void) dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(n_100));
T_ASSERT_NOT_EQUAL(strcmp(buf, "99.99"), 0); /* Would like to gett */
- dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_round_float(n_100, 2));
+ (void) dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_round_float(n_100, 2));
T_ASSERT_EQUAL(strcmp(buf, "99.99"), 0);
- dm_snprintf(buf, sizeof(buf), "%.3f", dm_percent_to_round_float(n_100, 3));
+ (void) dm_snprintf(buf, sizeof(buf), "%.3f", dm_percent_to_round_float(n_100, 3));
T_ASSERT_EQUAL(strcmp(buf, "99.999"), 0);
- dm_snprintf(buf, sizeof(buf), "%.4f", dm_percent_to_round_float(n_100, 4));
+ (void) dm_snprintf(buf, sizeof(buf), "%.4f", dm_percent_to_round_float(n_100, 4));
T_ASSERT_EQUAL(strcmp(buf, "99.9999"), 0);
- dm_snprintf(buf, sizeof(buf), "%d", (int)dm_percent_to_round_float(n_100, 0));
+ (void) dm_snprintf(buf, sizeof(buf), "%d", (int)dm_percent_to_round_float(n_100, 0));
T_ASSERT_EQUAL(strcmp(buf, "99"), 0);
}
@@ -66,22 +66,22 @@ static void test_percent_0(void *fixture)
T_ASSERT_EQUAL(p1_0, DM_PERCENT_0);
T_ASSERT_NOT_EQUAL(n_0, DM_PERCENT_0);
- dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(p_0));
+ (void) dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(p_0));
T_ASSERT_EQUAL(strcmp(buf, "0.00"), 0);
- dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(p1_0));
+ (void) dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(p1_0));
T_ASSERT_EQUAL(strcmp(buf, "0.00"), 0);
- dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(n_0));
+ (void) dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_float(n_0));
T_ASSERT_NOT_EQUAL(strcmp(buf, "0.01"), 0);
- dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_round_float(n_0, 2));
+ (void) dm_snprintf(buf, sizeof(buf), "%.2f", dm_percent_to_round_float(n_0, 2));
T_ASSERT_EQUAL(strcmp(buf, "0.01"), 0);
- dm_snprintf(buf, sizeof(buf), "%.3f", dm_percent_to_round_float(n_0, 3));
+ (void) dm_snprintf(buf, sizeof(buf), "%.3f", dm_percent_to_round_float(n_0, 3));
T_ASSERT_EQUAL(strcmp(buf, "0.001"), 0);
- dm_snprintf(buf, sizeof(buf), "%d", (int)dm_percent_to_round_float(n_0, 0));
+ (void) dm_snprintf(buf, sizeof(buf), "%d", (int)dm_percent_to_round_float(n_0, 0));
T_ASSERT_EQUAL(strcmp(buf, "1"), 0);
}
2 years, 7 months
main - cov: validate syscall result
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=055406bb398ddf60f18...
Commit: 055406bb398ddf60f18c545baffcec4ee4d5646e
Parent: 9721f3e0ff6fd841b62b6bcccceee2ebb914e96b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 10:31:45 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: validate syscall result
---
test/lib/brick-shelltest.h | 3 ++-
test/lib/not.c | 6 +++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/test/lib/brick-shelltest.h b/test/lib/brick-shelltest.h
index 0b1f9dfee..6bc02e0d2 100644
--- a/test/lib/brick-shelltest.h
+++ b/test/lib/brick-shelltest.h
@@ -424,7 +424,8 @@ struct FdSink : Sink {
{
TimedBuffer::Line line = stream.shift( force );
std::string out = fmt.format( line );
- write( fd, out.c_str(), out.length() );
+ if ( write( fd, out.c_str(), out.length() ) < (int)out.length() )
+ perror( "short write" );
}
virtual void sync( bool force ) {
diff --git a/test/lib/not.c b/test/lib/not.c
index a5c52a8e6..0cff13062 100644
--- a/test/lib/not.c
+++ b/test/lib/not.c
@@ -86,7 +86,11 @@ int main(int args, char **argv) {
/* should not be accessible */
return FAILURE;
} else { /* parent */
- waitpid(pid, &status, 0);
+ if (waitpid(pid, &status, 0) < 0) {
+ fprintf(stderr, "Process %d failed on waitpid.\n", pid);
+ return FAILURE;
+ }
+
if (!WIFEXITED(status)) {
if (WIFSIGNALED(status))
fprintf(stderr,
2 years, 7 months
main - cov: test for fixture being NULL pointer
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9721f3e0ff6fd841b62...
Commit: 9721f3e0ff6fd841b62b6bcccceee2ebb914e96b
Parent: 3f946bfce72952bc9e775ec41278dd33afbc9eb1
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 10:28:07 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: test for fixture being NULL pointer
Explicit check for teoretical NULL pointer passed as fixture.
---
test/unit/bcache_t.c | 8 +++++---
test/unit/bcache_utils_t.c | 12 +++++++-----
test/unit/bitset_t.c | 3 ++-
test/unit/io_engine_t.c | 16 +++++++++-------
test/unit/radix_tree_t.c | 3 ++-
5 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/test/unit/bcache_t.c b/test/unit/bcache_t.c
index 3231b76e0..2668d3ff6 100644
--- a/test/unit/bcache_t.c
+++ b/test/unit/bcache_t.c
@@ -349,10 +349,12 @@ static struct fixture *_fixture_init(sector_t block_size, unsigned nr_cache_bloc
static void _fixture_exit(struct fixture *f)
{
- _expect(f->me, E_DESTROY);
- bcache_destroy(f->cache);
+ if (f) {
+ _expect(f->me, E_DESTROY);
+ bcache_destroy(f->cache);
- free(f);
+ free(f);
+ }
}
static void *_small_fixture_init(void)
diff --git a/test/unit/bcache_utils_t.c b/test/unit/bcache_utils_t.c
index df2826977..48dab142e 100644
--- a/test/unit/bcache_utils_t.c
+++ b/test/unit/bcache_utils_t.c
@@ -109,11 +109,13 @@ static void _fix_exit(void *fixture)
{
struct fixture *f = fixture;
- bcache_destroy(f->cache);
- close(f->fd);
- bcache_clear_fd(f->di);
- unlink(f->fname);
- free(f);
+ if (f) {
+ bcache_destroy(f->cache);
+ (void) close(f->fd);
+ bcache_clear_fd(f->di);
+ (void) unlink(f->fname);
+ free(f);
+ }
}
//----------------------------------------------------------------
diff --git a/test/unit/bitset_t.c b/test/unit/bitset_t.c
index 4ee4f1c22..1e74e12d2 100644
--- a/test/unit/bitset_t.c
+++ b/test/unit/bitset_t.c
@@ -31,7 +31,8 @@ static void *_mem_init(void) {
static void _mem_exit(void *mem)
{
- dm_pool_destroy(mem);
+ if (mem)
+ dm_pool_destroy(mem);
}
static void test_get_next(void *fixture)
diff --git a/test/unit/io_engine_t.c b/test/unit/io_engine_t.c
index 89fa4b787..d45d8ffa7 100644
--- a/test/unit/io_engine_t.c
+++ b/test/unit/io_engine_t.c
@@ -104,13 +104,15 @@ static void _fix_exit(void *fixture)
{
struct fixture *f = fixture;
- close(f->fd);
- bcache_clear_fd(f->di);
- unlink(f->fname);
- free(f->data);
- if (f->e)
- f->e->destroy(f->e);
- free(f);
+ if (f) {
+ (void) close(f->fd);
+ bcache_clear_fd(f->di);
+ (void) unlink(f->fname);
+ free(f->data);
+ if (f->e)
+ f->e->destroy(f->e);
+ free(f);
+ }
}
static void _test_create(void *fixture)
diff --git a/test/unit/radix_tree_t.c b/test/unit/radix_tree_t.c
index 54bc40670..88c8bd5a7 100644
--- a/test/unit/radix_tree_t.c
+++ b/test/unit/radix_tree_t.c
@@ -28,7 +28,8 @@ static void *rt_init(void)
static void rt_exit(void *fixture)
{
- radix_tree_destroy(fixture);
+ if (fixture)
+ radix_tree_destroy(fixture);
}
static void test_create_destroy(void *fixture)
2 years, 7 months
main - cov: capture runtime exception
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3f946bfce72952bc9e7...
Commit: 3f946bfce72952bc9e775ec41278dd33afbc9eb1
Parent: d5c82b0e73421eb57bf36578b39813915af4676b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 10:26:26 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: capture runtime exception
---
test/lib/brick-shelltest.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/test/lib/brick-shelltest.h b/test/lib/brick-shelltest.h
index 8637d8a9f..0b1f9dfee 100644
--- a/test/lib/brick-shelltest.h
+++ b/test/lib/brick-shelltest.h
@@ -536,7 +536,11 @@ struct FileSource : Source {
lseek( fd, 0, SEEK_END );
}
if ( fd >= 0 )
- Source::sync( s );
+ try {
+ Source::sync( s );
+ } catch (...) {
+ perror("failed to sync");
+ }
}
};
2 years, 7 months
main - cov: better defined constructors
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d5c82b0e73421eb57bf...
Commit: d5c82b0e73421eb57bf36578b39813915af4676b
Parent: ebd150366f0852e7ebd32e7743e6a135138320a0
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 10:26:05 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: better defined constructors
Ensure C++ initializes all struct members.
Also some deterministic buffer initialization.
---
test/lib/brick-shelltest.h | 8 +++++---
test/unit/bcache_utils_t.c | 3 ++-
test/unit/run.c | 1 +
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/test/lib/brick-shelltest.h b/test/lib/brick-shelltest.h
index b58f3d684..8637d8a9f 100644
--- a/test/lib/brick-shelltest.h
+++ b/test/lib/brick-shelltest.h
@@ -755,7 +755,7 @@ struct TestCase {
}
void pipe() {
- int fds[2];
+ int fds[2] = { 0 };
if (socketpair( PF_UNIX, SOCK_STREAM, 0, fds )) {
perror("socketpair");
@@ -981,7 +981,9 @@ struct TestCase {
}
TestCase( Journal &j, Options opt, std::string path, std::string _name, std::string _flavour )
- : child( path ), name( _name ), flavour( _flavour ), timeout( false ),
+ : child( path ), name( _name ), flavour( _flavour ),
+ iobuf( NULL ), usage( { 0 } ), status( 0 ), timeout( false ),
+ pid( 0 ), start( 0 ), end( 0 ), silent_start( 0 ),
last_update( 0 ), last_heartbeat( 0 ), options( opt ), journal( &j )
{
}
@@ -1085,7 +1087,7 @@ struct Main {
return journal.count( Journal::FAILED ) || journal.count( Journal::TIMEOUT ) ? 1 : 0;
}
- Main( Options o ) : die( false ), journal( o.outdir ), options( o ) {}
+ Main( Options o ) : die( false ), start( 0 ), journal( o.outdir ), options( o ) {}
};
namespace {
diff --git a/test/unit/bcache_utils_t.c b/test/unit/bcache_utils_t.c
index 573fc1533..df2826977 100644
--- a/test/unit/bcache_utils_t.c
+++ b/test/unit/bcache_utils_t.c
@@ -52,9 +52,10 @@ static void *_fix_init(struct io_engine *engine)
uint8_t buffer[T_BLOCK_SIZE];
struct fixture *f = malloc(sizeof(*f));
unsigned b, i;
- struct statvfs fsdata;
+ struct statvfs fsdata = { 0 };
static int _runs_is_tmpfs = -1;
+ memset(buffer, 0, sizeof(buffer));
if (_runs_is_tmpfs == -1) {
// With testing in tmpfs directory O_DIRECT cannot be used
// tmpfs has f_fsid == 0 (unsure if this is best guess)
diff --git a/test/unit/run.c b/test/unit/run.c
index 281991c51..0abd47246 100644
--- a/test/unit/run.c
+++ b/test/unit/run.c
@@ -271,6 +271,7 @@ int main(int argc, char **argv)
fprintf(stderr, "out of memory\n");
exit(1);
}
+ memset(t_array, 0, sizeof(*t_array) * nr_tests);
i = 0;
dm_list_iterate_items (ts, &suites)
2 years, 7 months
main - cov: add explicit NULL pointer check
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ebd150366f0852e7ebd...
Commit: ebd150366f0852e7ebd32e7743e6a135138320a0
Parent: 752a9ec4b44198554b9f998ed6e4a837878fc49f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 10:24:30 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: add explicit NULL pointer check
Make obvious to coverity strcmp() is not getting NULL pointer.
---
lib/config/config.c | 2 +-
libdm/dm-tools/dmsetup.c | 7 ++++---
test/unit/run.c | 2 +-
tools/command.c | 4 ++--
4 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index aedbb2b1e..0cb0da121 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -932,7 +932,7 @@ static int _check_value_differs_from_default(struct cft_check_handle *handle,
} else {
str = v_def ? v_def->v.str
: cfg_def_get_default_value(handle->cmd, def, CFG_TYPE_STRING, NULL);
- diff = strcmp(str, v->v.str);
+ diff = str ? strcmp(str, v->v.str) : 0;
}
break;
case DM_CFG_EMPTY_ARRAY:
diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c
index f431f7509..f6d1ecf90 100644
--- a/libdm/dm-tools/dmsetup.c
+++ b/libdm/dm-tools/dmsetup.c
@@ -6426,9 +6426,10 @@ static const struct command *_find_command(const struct command *commands,
{
int i;
- for (i = 0; commands[i].name; i++)
- if (!strcmp(commands[i].name, name))
- return commands + i;
+ if (name)
+ for (i = 0; commands[i].name; i++)
+ if (!strcmp(commands[i].name, name))
+ return commands + i;
return NULL;
}
diff --git a/test/unit/run.c b/test/unit/run.c
index 206857159..281991c51 100644
--- a/test/unit/run.c
+++ b/test/unit/run.c
@@ -240,7 +240,7 @@ static unsigned _filter(const char *pattern, struct test_details **tests, unsign
}
for (i = 0; i < nr; i++)
- if (!regexec(&rx, tests[i]->path, 0, NULL, 0))
+ if (tests[i] && !regexec(&rx, tests[i]->path, 0, NULL, 0))
tests[found++] = tests[i];
regfree(&rx);
diff --git a/tools/command.c b/tools/command.c
index 48f572f7e..18ffd64ed 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -4015,9 +4015,9 @@ int main(int argc, char *argv[])
factor_common_options();
- if (primary)
+ if (primary && cmdname)
r = _print_man(cmdname, desfile, secondary);
- else if (secondary) {
+ else if (secondary && cmdname) {
r = 1;
_print_man_secondary(cmdname);
} else if (check) {
2 years, 7 months
main - cov: make read buffer obviously zero ended
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=752a9ec4b44198554b9...
Commit: 752a9ec4b44198554b9f998ed6e4a837878fc49f
Parent: 6c87e98ee367e1ff410470c09e6131697f0a7660
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 01:57:06 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: make read buffer obviously zero ended
Coverity doesn't get the idea from memset() here.
---
lib/config/config.c | 2 +-
tools/pvck.c | 5 ++---
tools/pvscan.c | 1 +
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index 25a87c983..aedbb2b1e 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -522,7 +522,7 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
if (!(dev->flags & DEV_REGULAR) || size2)
use_plain_read = 0;
- if (!(buf = malloc(size + size2))) {
+ if (!(buf = zalloc(size + size2))) {
log_error("Failed to allocate circular buffer.");
return 0;
}
diff --git a/tools/pvck.c b/tools/pvck.c
index 629e1feee..0d1bc1b17 100644
--- a/tools/pvck.c
+++ b/tools/pvck.c
@@ -2955,7 +2955,7 @@ static int _read_metadata_file(struct cmd_context *cmd, struct metadata_file *mf
goto out;
}
- if (!(text_buf = zalloc(text_size + 1)))
+ if (!(text_buf = malloc(text_size + 1)))
goto_out;
rv = read(fd, text_buf, text_size);
@@ -2964,8 +2964,7 @@ static int _read_metadata_file(struct cmd_context *cmd, struct metadata_file *mf
free(text_buf);
goto out;
}
-
- text_size += 1; /* null terminating byte */
+ text_buf[text_size++] = 0; /* null terminating byte */
if (close(fd))
stack;
diff --git a/tools/pvscan.c b/tools/pvscan.c
index ec33c9a9a..b19b74b3e 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -223,6 +223,7 @@ static int _online_pvid_file_read(char *path, int *major, int *minor, char *vgna
log_warn("No info in %s", path);
return 0;
}
+ buf[rv] = 0; /* \0 terminated buffer */
if (sscanf(buf, "%d:%d", major, minor) != 2) {
log_warn("No device numbers in %s", path);
2 years, 7 months
main - cov: check for possible NULL segtype
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6c87e98ee367e1ff410...
Commit: 6c87e98ee367e1ff410470c09e6131697f0a7660
Parent: bfc6fe2bac8ac262075271c2f6649b28cd04f883
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 01:51:29 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: check for possible NULL segtype
Although likely impossible to ever miss ERROR segtype,
make analyzer hapier.
---
lib/metadata/lv_manip.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index e2efbf03a..1a4e613a7 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -1699,6 +1699,10 @@ int lv_empty(struct logical_volume *lv)
int replace_lv_with_error_segment(struct logical_volume *lv)
{
uint32_t len = lv->le_count;
+ struct segment_type *segtype;
+
+ if (!(segtype = get_segtype_from_string(lv->vg->cmd, SEG_TYPE_NAME_ERROR)))
+ return_0;
if (len && !lv_empty(lv))
return_0;
@@ -1717,7 +1721,7 @@ int replace_lv_with_error_segment(struct logical_volume *lv)
/* FIXME Check for any attached LVs that will become orphans e.g. mirror logs */
- if (!lv_add_virtual_segment(lv, 0, len, get_segtype_from_string(lv->vg->cmd, SEG_TYPE_NAME_ERROR)))
+ if (!lv_add_virtual_segment(lv, 0, len, segtype))
return_0;
return 1;
2 years, 7 months
main - cov: ensure data is not derefenced
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bfc6fe2bac8ac262075...
Commit: bfc6fe2bac8ac262075271c2f6649b28cd04f883
Parent: 3e7e9cc5e6abc4ddb1777e7c7b9d7bc42a7f57a7
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 20 01:46:43 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: ensure data is not derefenced
Ensure all hypothetical paths cannot dereference NULL *(u->data).
---
lib/device/bcache-utils.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/device/bcache-utils.c b/lib/device/bcache-utils.c
index 85ec07aa6..82adb89a9 100644
--- a/lib/device/bcache-utils.c
+++ b/lib/device/bcache-utils.c
@@ -164,8 +164,10 @@ static bool _write_partial(struct updater *u, int di, block_address bb,
if (!bcache_get(u->cache, di, bb, GF_DIRTY, &b))
return false;
- memcpy(((unsigned char *) b->data) + offset, u->data, len);
- u->data = ((unsigned char *) u->data) + len;
+ if (u->data) {
+ memcpy(((unsigned char *) b->data) + offset, u->data, len);
+ u->data = ((unsigned char *) u->data) + len;
+ }
bcache_put(b);
return true;
@@ -246,7 +248,7 @@ bool bcache_zero_bytes(struct bcache *cache, int di, uint64_t start, size_t len)
static bool _set_partial(struct updater *u, int di, block_address bb, uint64_t offset, size_t len)
{
struct block *b;
- uint8_t val = *((uint8_t *) u->data);
+ uint8_t val = (u->data) ? *((uint8_t *) u->data) : 0;
if (!bcache_get(u->cache, di, bb, GF_DIRTY, &b))
return false;
@@ -260,7 +262,7 @@ static bool _set_partial(struct updater *u, int di, block_address bb, uint64_t o
static bool _set_whole(struct updater *u, int di, block_address bb, block_address be)
{
struct block *b;
- uint8_t val = *((uint8_t *) u->data);
+ uint8_t val = (u->data) ? *((uint8_t *) u->data) : 0;
uint64_t len = bcache_block_sectors(u->cache) * 512;
for (; bb != be; bb++) {
2 years, 7 months
main - cov: handle better leak reports
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3e7e9cc5e6abc4ddb17...
Commit: 3e7e9cc5e6abc4ddb1777e7c7b9d7bc42a7f57a7
Parent: 825e49a2447810a806905723bc91072eb7b8b423
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Sep 19 20:27:34 2021 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Sep 20 14:26:09 2021 +0200
cov: handle better leak reports
Rewrite code so the leaks are eliminated from Coverity.
---
tools/command.c | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/tools/command.c b/tools/command.c
index 37f6a6153..48f572f7e 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -757,6 +757,9 @@ static void _set_opt_def(struct cmd_context *cmdtool, struct command *cmd, char
def->num = (uint64_t)atoi(name);
if (val_enum == conststr_VAL) {
+#ifdef MAN_PAGE_GENERATOR
+ free((void*)def->str);
+#endif
def->str = dm_pool_strdup(cmdtool->libmem, name);
if (!def->str) {
@@ -1539,20 +1542,27 @@ int define_commands(struct cmd_context *cmdtool, const char *run_name)
*/
if (_is_desc_line(line_argv[0]) && !skip && cmd) {
- char *desc = dm_pool_strdup(cmdtool->libmem, line_orig);
- if (cmd->desc && desc) {
- int newlen = strlen(cmd->desc) + strlen(desc) + 2;
+ if (cmd->desc) {
+ size_t newlen = strlen(cmd->desc) + strlen(line_orig) + 2;
char *newdesc = dm_pool_alloc(cmdtool->libmem, newlen);
- if (newdesc) {
- snprintf(newdesc, newlen, "%s %s", cmd->desc, desc);
- cmd->desc = newdesc;
- } else {
+
+ if (!newdesc) {
/* FIXME */
stack;
return 0;
}
- } else
- cmd->desc = desc;
+
+ snprintf(newdesc, newlen, "%s %s", cmd->desc, line_orig);
+#ifdef MAN_PAGE_GENERATOR
+ free((void*)cmd->desc);
+#endif
+ cmd->desc = newdesc;
+ } else if (!(cmd->desc = dm_pool_strdup(cmdtool->libmem, line_orig))) {
+ /* FIXME */
+ stack;
+ return 0;
+ }
+
continue;
}
@@ -1572,6 +1582,9 @@ int define_commands(struct cmd_context *cmdtool, const char *run_name)
}
if (_is_id_line(line_argv[0]) && cmd) {
+#ifdef MAN_PAGE_GENERATOR
+ free((void*)cmd->command_id);
+#endif
cmd->command_id = dm_pool_strdup(cmdtool->libmem, line_argv[1]);
if (!cmd->command_id) {
@@ -3674,8 +3687,6 @@ static int _print_man(char *name, char *des_file, int secondary)
printf(".P\n");
}
}
-
- continue;
}
return 1;
2 years, 7 months