mirror of
https://github.com/ceph/ceph
synced 2025-01-20 01:51:34 +00:00
Merge PR #29316 into master
* refs/pull/29316/head: common,tools: make sure the destination buffer can handle the size of the string src/tools: initialize variables before the goto statement src/mount: check before dereference buf src/crush: check before dereference out2 src/test: s/strcpy/strncpy Reviewed-by: Neha Ojha <nojha@redhat.com> Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
commit
c16284d6af
@ -249,7 +249,7 @@ void collect_sys_info(map<string, string> *m, CephContext *cct)
|
|||||||
break;
|
break;
|
||||||
char key[40];
|
char key[40];
|
||||||
long long value;
|
long long value;
|
||||||
int r = sscanf(line, "%s %lld", key, &value);
|
int r = sscanf(line, "%39s %lld", key, &value);
|
||||||
if (r == 2) {
|
if (r == 2) {
|
||||||
if (strcmp(key, "MemTotal:") == 0)
|
if (strcmp(key, "MemTotal:") == 0)
|
||||||
(*m)["mem_total_kb"] = boost::lexical_cast<string>(value);
|
(*m)["mem_total_kb"] = boost::lexical_cast<string>(value);
|
||||||
|
@ -792,11 +792,11 @@ static void crush_choose_indep(const struct crush_map *map,
|
|||||||
out2, rep,
|
out2, rep,
|
||||||
recurse_tries, 0,
|
recurse_tries, 0,
|
||||||
0, NULL, r, choose_args);
|
0, NULL, r, choose_args);
|
||||||
if (out2[rep] == CRUSH_ITEM_NONE) {
|
if (out2 && out2[rep] == CRUSH_ITEM_NONE) {
|
||||||
/* placed nothing; no leaf */
|
/* placed nothing; no leaf */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (out2) {
|
||||||
/* we already have a leaf! */
|
/* we already have a leaf! */
|
||||||
out2[rep] = item;
|
out2[rep] = item;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,10 @@ static char *mount_resolve_src(const char *orig_str)
|
|||||||
char *mount_path;
|
char *mount_path;
|
||||||
char *src;
|
char *src;
|
||||||
char *buf = strdup(orig_str);
|
char *buf = strdup(orig_str);
|
||||||
|
if (!buf) {
|
||||||
|
fprintf(stderr, "%s: failed to allocate memory\n", __func__);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
mount_path = strstr(buf, ":/");
|
mount_path = strstr(buf, ":/");
|
||||||
if (!mount_path) {
|
if (!mount_path) {
|
||||||
|
@ -77,7 +77,8 @@ int TestWatchNotify::list_watchers(int64_t pool_id, const std::string& nspace,
|
|||||||
watcher->watch_handles.begin();
|
watcher->watch_handles.begin();
|
||||||
it != watcher->watch_handles.end(); ++it) {
|
it != watcher->watch_handles.end(); ++it) {
|
||||||
obj_watch_t obj;
|
obj_watch_t obj;
|
||||||
strcpy(obj.addr, it->second.addr.c_str());
|
strncpy(obj.addr, it->second.addr.c_str(), sizeof(obj.addr) - 1);
|
||||||
|
obj.addr[sizeof(obj.addr) - 1] = '\0';
|
||||||
obj.watcher_id = static_cast<int64_t>(it->second.gid);
|
obj.watcher_id = static_cast<int64_t>(it->second.gid);
|
||||||
obj.cookie = it->second.handle;
|
obj.cookie = it->second.handle;
|
||||||
obj.timeout_seconds = 30;
|
obj.timeout_seconds = 30;
|
||||||
|
@ -81,7 +81,8 @@ public:
|
|||||||
expect.WillOnce(Return(r));
|
expect.WillOnce(Return(r));
|
||||||
} else {
|
} else {
|
||||||
obj_watch_t watcher;
|
obj_watch_t watcher;
|
||||||
strcpy(watcher.addr, (address + ":0/0").c_str());
|
strncpy(watcher.addr, (address + ":0/0").c_str(), sizeof(watcher.addr) - 1);
|
||||||
|
watcher.addr[sizeof(watcher.addr) - 1] = '\0';
|
||||||
watcher.watcher_id = 0;
|
watcher.watcher_id = 0;
|
||||||
watcher.cookie = watch_handle;
|
watcher.cookie = watch_handle;
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ int Dumper::undump(const char *dump_file, bool force)
|
|||||||
if (strstr(buf, "fsid")) {
|
if (strstr(buf, "fsid")) {
|
||||||
uuid_d fsid;
|
uuid_d fsid;
|
||||||
char fsid_str[40];
|
char fsid_str[40];
|
||||||
sscanf(strstr(buf, "fsid"), "fsid %s", fsid_str);
|
sscanf(strstr(buf, "fsid"), "fsid %39s", fsid_str);
|
||||||
r = fsid.parse(fsid_str);
|
r = fsid.parse(fsid_str);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
derr << "Invalid fsid" << dendl;
|
derr << "Invalid fsid" << dendl;
|
||||||
|
@ -106,9 +106,12 @@ out_err:
|
|||||||
static int testrados(void)
|
static int testrados(void)
|
||||||
{
|
{
|
||||||
char tmp[32];
|
char tmp[32];
|
||||||
int i, r;
|
int i, r, safe;
|
||||||
int ret = 1; //set 1 as error case
|
int ret = 1; //set 1 as error case
|
||||||
rados_t cl;
|
rados_t cl;
|
||||||
|
const char *oid = "foo_object";
|
||||||
|
const char *exkeys[] = { "a", "b", "c", NULL };
|
||||||
|
const char *exvals[] = { "1", "2", "3", NULL };
|
||||||
|
|
||||||
if (rados_create(&cl, NULL) < 0) {
|
if (rados_create(&cl, NULL) < 0) {
|
||||||
printf("error initializing\n");
|
printf("error initializing\n");
|
||||||
@ -217,7 +220,6 @@ static int testrados(void)
|
|||||||
char buf[128], buf2[128];
|
char buf[128], buf2[128];
|
||||||
time(&tm);
|
time(&tm);
|
||||||
snprintf(buf, 128, "%s", ctime(&tm));
|
snprintf(buf, 128, "%s", ctime(&tm));
|
||||||
const char *oid = "foo_object";
|
|
||||||
r = rados_write(io_ctx, oid, buf, strlen(buf) + 1, 0);
|
r = rados_write(io_ctx, oid, buf, strlen(buf) + 1, 0);
|
||||||
printf("rados_write = %d\n", r);
|
printf("rados_write = %d\n", r);
|
||||||
r = rados_read(io_ctx, oid, buf2, sizeof(buf2), 0);
|
r = rados_read(io_ctx, oid, buf2, sizeof(buf2), 0);
|
||||||
@ -238,8 +240,6 @@ static int testrados(void)
|
|||||||
goto out_err_cleanup;
|
goto out_err_cleanup;
|
||||||
if (do_rados_getxattr(io_ctx, oid, "c", "3"))
|
if (do_rados_getxattr(io_ctx, oid, "c", "3"))
|
||||||
goto out_err_cleanup;
|
goto out_err_cleanup;
|
||||||
const char *exkeys[] = { "a", "b", "c", NULL };
|
|
||||||
const char *exvals[] = { "1", "2", "3", NULL };
|
|
||||||
if (do_rados_getxattrs(io_ctx, oid, exkeys, exvals))
|
if (do_rados_getxattrs(io_ctx, oid, exkeys, exvals))
|
||||||
goto out_err_cleanup;
|
goto out_err_cleanup;
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ static int testrados(void)
|
|||||||
rados_completion_t c;
|
rados_completion_t c;
|
||||||
rados_aio_create_completion(0, 0, 0, &c);
|
rados_aio_create_completion(0, 0, 0, &c);
|
||||||
rados_aio_write(io_ctx, "c", c, buf, 100, 0);
|
rados_aio_write(io_ctx, "c", c, buf, 100, 0);
|
||||||
int safe = rados_aio_is_safe(c);
|
safe = rados_aio_is_safe(c);
|
||||||
printf("a should not yet be safe and ... %s\n", safe ? "is":"is not");
|
printf("a should not yet be safe and ... %s\n", safe ? "is":"is not");
|
||||||
assert(!safe);
|
assert(!safe);
|
||||||
rados_aio_flush(io_ctx);
|
rados_aio_flush(io_ctx);
|
||||||
|
Loading…
Reference in New Issue
Block a user