From 61e8ace32a9617b02f1daff80b431c7d2a756023 Mon Sep 17 00:00:00 2001 From: Dhruv Maroo Date: Sat, 31 Dec 2022 14:27:19 +0530 Subject: [PATCH] Fixing some Coverity issues (#3261) * Use signed long long for `src_readlen`, so we can check for -1 * Fixes Coverity defect 396947 and 356103 * Replace Unicode quotes with ASCII * Ue signed structure in case -1 is returned (CID 396933) * Need signed to check negative (CID 395560) * Fix memleaks in `test_autocmplt_global` * Related CIDs: 356309, 356307 * Set initial value of `ret` to false --- librz/core/cmd/cmd_shell.c | 2 +- librz/util/compression.c | 14 +++++++------- test/integration/test_autocmplt.c | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/librz/core/cmd/cmd_shell.c b/librz/core/cmd/cmd_shell.c index 11fd3ea496..1d2fba06e8 100644 --- a/librz/core/cmd/cmd_shell.c +++ b/librz/core/cmd/cmd_shell.c @@ -111,7 +111,7 @@ RZ_IPI RzCmdStatus rz_cmd_shell_cp_handler(RzCore *core, int argc, const char ** // cd RZ_IPI RzCmdStatus rz_cmd_shell_cd_handler(RzCore *core, int argc, const char **argv) { static char *olddir = NULL; - bool ret = true; + bool ret = false; const char *dir = "~"; if (argc > 1) { dir = argv[1]; diff --git a/librz/util/compression.c b/librz/util/compression.c index 3592c4ba87..7f794ed889 100644 --- a/librz/util/compression.c +++ b/librz/util/compression.c @@ -58,7 +58,7 @@ static const char *gzerr(int n) { * \param srcLen source bytes length * \param srcConsumed consumed source bytes length * \param dstLen uncompressed bytes length - * \param wbits the size of the history buffer (or “window size”), and what header and trailer format is expected. + * \param wbits the size of the history buffer (or "window size"), and what header and trailer format is expected. * \return ptr to uncompressed */ RZ_API ut8 *rz_inflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits) { @@ -126,7 +126,7 @@ err_exit: * \param srcLen source bytes length * \param srcConsumed consumed source bytes length * \param dstLen compressed bytes length - * \param wbits the size of the history buffer (or “window size”), and what header and trailer format is expected. + * \param wbits the size of the history buffer (or "window size"), and what header and trailer format is expected. * \return ptr to compressed */ RZ_API ut8 *rz_deflatew(RZ_NONNULL const ut8 *src, int srcLen, int *srcConsumed, int *dstLen, int wbits) { @@ -194,7 +194,7 @@ err_exit: * \param dst destination buffer * \param block_size block sizes to use while deflating data * \param src_consumed consumed source buffer length - * \param wbits the size of the history buffer (or “window size”), and what header and trailer format is expected. + * \param wbits the size of the history buffer (or "window size"), and what header and trailer format is expected. * \return true if successful; false otherwise */ RZ_API bool rz_deflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits) { @@ -204,7 +204,7 @@ RZ_API bool rz_deflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, int err = 0, flush = Z_NO_FLUSH; bool ret = true; ut64 dst_cursor = 0, src_cursor = 0; - ut64 src_readlen = 0; + st64 src_readlen = 0; z_stream stream; memset(&stream, 0, sizeof(z_stream)); @@ -260,7 +260,7 @@ return_goto: * \param dst destination buffer * \param block_size block sizes to use while inflating data * \param src_consumed consumed source buffer length - * \param wbits the size of the history buffer (or “window size”), and what header and trailer format is expected. + * \param wbits the size of the history buffer (or "window size"), and what header and trailer format is expected. * \return true if successful; false otherwise */ RZ_API bool rz_inflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut64 block_size, ut8 *src_consumed, int wbits) { @@ -270,7 +270,7 @@ RZ_API bool rz_inflatew_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, int err = 0, flush = Z_NO_FLUSH; bool ret = true; ut64 src_cursor = 0; - ut64 src_readlen = 0; + st64 src_readlen = 0; z_stream stream; memset(&stream, 0, sizeof(z_stream)); @@ -388,7 +388,7 @@ static bool lzma_action_buf(RZ_NONNULL RzBuffer *src, RZ_NONNULL RzBuffer *dst, ut8 *inbuf = RZ_NEWS(ut8, block_size); ut8 *outbuf = RZ_NEWS(ut8, block_size); ut64 src_cursor = 0; - ut64 src_readlen = 0; + st64 src_readlen = 0; strm.next_in = NULL; strm.avail_in = 0; diff --git a/test/integration/test_autocmplt.c b/test/integration/test_autocmplt.c index 9af4a13715..e01d8b67bd 100644 --- a/test/integration/test_autocmplt.c +++ b/test/integration/test_autocmplt.c @@ -439,6 +439,8 @@ static bool test_autocmplt_global(void) { mu_assert_notnull(parser, "create type parser"); char *errmsg = NULL; RzType *typ = rz_type_parse_string_single(parser, "int", &errmsg); + free(errmsg); + mu_assert_notnull(typ, "parsed type"); rz_analysis_var_global_set_type(glob2, typ); @@ -457,6 +459,7 @@ static bool test_autocmplt_global(void) { mu_assert_streq(rz_pvector_at(&r->options, 1), "GCHR", "GCHR found"); rz_line_ns_completion_result_free(r); + rz_type_parser_free(parser); rz_core_free(core); mu_end; }