Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for issues found during SCA #21419

Merged
merged 14 commits into from Apr 16, 2018
Merged

Fixes for issues found during SCA #21419

merged 14 commits into from Apr 16, 2018

Conversation

dalgaaf
Copy link
Contributor

@dalgaaf dalgaaf commented Apr 13, 2018

Fixes for:

  • memory leaks (delete, realloc errors)
  • format qualifiers
  • boundary checks
  • fix parameter to variadic function calls
  • fix uninitialized variables

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
@tchaikov tchaikov requested a review from dillaman April 13, 2018 14:58
@tchaikov tchaikov added the rbd label Apr 13, 2018
@@ -274,6 +274,7 @@ int Image<I>::deep_copy(I *src, librados::IoCtx& dest_md_ctx,
r = dest->state->open(false);
if (r < 0) {
lderr(cct) << "failed to read newly created header" << dendl;
delete dest;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎 -- ImageState::open will automatically delete the ImageCtx upon failure [1]

[1] https://github.com/ceph/ceph/blob/master/src/librbd/ImageState.cc#L254

@@ -1772,6 +1772,7 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
r = dest->state->open(false);
if (r < 0) {
lderr(cct) << "failed to read newly created header" << dendl;
delete dest;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎 -- ImageState::open will automatically delete the ImageCtx upon failure [1]

[1] https://github.com/ceph/ceph/blob/master/src/librbd/ImageState.cc#L254

@@ -200,22 +200,22 @@ void CephBroker::read(ResponseCallbackRead *cb, uint32_t fd, uint32_t amount) {

if (!m_open_file_map.get(fd, fdata)) {
char errbuf[32];
sprintf(errbuf, "%d", fd);
sprintf(errbuf, "%u", fd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd better to print an uint32_t using the macro of PRIu32 instead of %u, which works on platforms with 32bit integers but not on some other platforms.

@@ -152,7 +152,7 @@ OpTracker::OpTracker(CephContext *cct_, bool tracking, uint32_t num_shards):
lock("OpTracker::lock"), cct(cct_) {
for (uint32_t i = 0; i < num_optracker_shards; i++) {
char lock_name[32] = {0};
snprintf(lock_name, sizeof(lock_name), "%s:%d", "OpTracker::ShardedLock", i);
snprintf(lock_name, sizeof(lock_name), "%s:%u", "OpTracker::ShardedLock", i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use PRIu32 if you please.

src/osd/OSD.h Outdated
@@ -1733,7 +1733,7 @@ class OSD : public Dispatcher,
auto &&sdata = osd->shards[i];

char queue_name[32] = {0};
snprintf(queue_name, sizeof(queue_name), "%s%d", "OSD:ShardedOpWQ:", i);
snprintf(queue_name, sizeof(queue_name), "%s%u", "OSD:ShardedOpWQ:", i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRIu32

sizeof(struct SaveEvent)*newsize);
if (!sav_events) {
void *_realloc = NULL;
if ((_realloc = realloc(sav_events, izeof(struct SaveEvent)*newsize)) == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/izeof/sizeof/, could use "if with initialization" introduced by C++17, like

if (void* new_events = realloc(sav_events, sizeof(struct SaveEvent)*newsize)); !new_events) {
  lderr(cct) << __func__ << " unable to realloc memory: "
                               << cpp_strerror(errno) << dendl;
  free(sav_events);
  return -ENOMEM;
} else {
  sav_events = new_events;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, it compiled here fine.

@@ -1048,7 +1048,7 @@ struct rgw_bucket {
uint64_t id;
decode(id, bl);
char buf[16];
snprintf(buf, sizeof(buf), "%llu", (long long)id);
snprintf(buf, sizeof(buf), "%" PRIu64 , id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the space before ","

cb->error(Error::DFSBROKER_BAD_FILE_HANDLE, errbuf);
return;
}

int r;
if ((r = ceph_fsync(cmount, fdata->fd, true)) != 0) {
std::string errs(cpp_strerror(r));
HT_ERRORF("flush failed: fd=%d ceph_fd=%d - %s", fd, fdata->fd, errs.c_str());
HT_ERRORF("flush failed: fd=%lu ceph_fd=%d - %s", (Lu)fd, fdata->fd, errs.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRIu32


if (!m_open_file_map.get(fd, fdata)) {
char errbuf[32];
sprintf(errbuf, "%d", fd);
sprintf(errbuf, "%u", fd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRIu32

@@ -409,19 +409,19 @@ int CephBroker::rmdir_recursive(const char *directory) {
void CephBroker::flush(ResponseCallback *cb, uint32_t fd) {
OpenFileDataCephPtr fdata;

HT_DEBUGF("flush fd=%d", fd);
HT_DEBUGF("flush fd=%lu", (Lu)fd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRIu32

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, but this needs changes in more than these places since this kind of code is already used a lot in the file.

@@ -94,6 +94,7 @@ bool RGWBucketWebsiteConf::should_redirect(const string& key, const int http_err
RGWBWRoutingRule redirect_all_rule;
redirect_all_rule.redirect_info.redirect = redirect_all;
redirect_all.http_redirect_code = 301;
redirect_all_rule.condition = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please move this fix into the condition itself?

 struct RGWBWRoutingRuleCondition
 { 
   std::string key_prefix_equals;                                                    
-  uint16_t http_error_code_returned_equals;
+  uint16_t http_error_code_returned_equals = 0;

dalgaaf and others added 12 commits April 14, 2018 00:13
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Co-authored-by: Casey Bodley <cbodley@redhat.com>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix for:

[src/compressor/lz4/LZ4Compressor.h:105]: (style) Condition
 'r!=(int)compressed_pairs[i].first' is always true

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Fix for:

[src/krbd.cc:549]: (portability) Passing NULL after the last typed
 argument to a variadic function leads to undefined behaviour.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
@dalgaaf
Copy link
Contributor Author

dalgaaf commented Apr 14, 2018

make check failed ... looks like an issue with the agent:

"Agent went offline during the build"

@tchaikov
Copy link
Contributor

i guess the "make check" timed out.

retest this please

@dalgaaf
Copy link
Contributor Author

dalgaaf commented Apr 14, 2018

Seems to work now.

@tchaikov tchaikov merged commit 4f787e8 into master Apr 16, 2018
@tchaikov tchaikov deleted the wip-da-SCA-20180329 branch April 16, 2018 14:56
@tchaikov
Copy link
Contributor

@dalgaaf please note, we use ceph/ceph for "official" branches, like jewel, luminous, mimic, and it's advised to send PRs from our own repos instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants