From f98475dac42c8312232ed91a656241acbad589ea Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Fri, 6 May 2011 14:47:43 -0700 Subject: [PATCH] rados_sync: misc bugfixes Avoid using a temporary c_str pointer when it goes out of scope. Complain if XATTR_FULLNAME is empty, as well as missing. Signed-off-by: Colin McCabe --- src/rados_sync.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/rados_sync.cc b/src/rados_sync.cc index 7f218cbda24f0..c1243ecf0f9cb 100644 --- a/src/rados_sync.cc +++ b/src/rados_sync.cc @@ -152,9 +152,8 @@ public: BackedUpObject **obj) { int ret; - ostringstream oss; - oss << dir_name << "/" << file_name; - const char *obj_path = oss.str().c_str(); + char obj_path[strlen(dir_name) + strlen(file_name) + 2]; + snprintf(obj_path, sizeof(obj_path), "%s/%s", dir_name, file_name); FILE *fp = fopen(obj_path, "r"); if (!fp) { ret = errno; @@ -166,7 +165,7 @@ public: } int fd = fileno(fp); struct stat st_buf; - memset(&st_buf, 0, sizeof(struct stat)); + memset(&st_buf, 0, sizeof(st_buf)); ret = fstat(fd, &st_buf); if (ret) { ret = errno; @@ -178,8 +177,8 @@ public: // get fullname ssize_t res = fgetxattr(fd, XATTR_FULLNAME, NULL, 0); - if (res < 0) { - ret = errno; + if (res <= 0) { + ret = (res == 0) ? ENOATTR : errno; fclose(fp); if (ret == ENOATTR) cerr << "no " << XATTR_FULLNAME << " attribute found." << std::endl; -- 2.39.5