@@ -293,24 +293,41 @@ int Dumper::undump(const char *dump_file, bool force)
293293 }
294294
295295 if (recovered == 0 ) {
296+ // Check if the headers are available in the dump file
297+ if (!strstr (buf, " stripe_unit" )) {
298+ derr << " Invalid header, no 'stripe_unit' embedded" << dendl;
299+ ::close (fd);
300+ return -EINVAL;
301+ } else if (!strstr (buf, " stripe_count" )) {
302+ derr << " Invalid header, no 'stripe_count' embedded" << dendl;
303+ ::close (fd);
304+ return -EINVAL;
305+ } else if (!strstr (buf, " object_size" )) {
306+ derr << " Invalid header, no 'object_size' embedded" << dendl;
307+ ::close (fd);
308+ return -EINVAL;
309+ }
296310 auto && last_committed = journaler.get_last_committed ();
297311 stripe_unit = last_committed.layout .stripe_unit ;
298312 stripe_count = last_committed.layout .stripe_count ;
299313 object_size = last_committed.layout .object_size ;
300314 } else {
301315 // try to get layout from dump file header, if failed set layout to default
302- if (strstr (buf, " stripe_unit" )) {
303- sscanf (strstr (buf, " stripe_unit" ), " stripe_unit %lu" , &stripe_unit);
316+ char *p_stripe_unit = strstr (buf, " stripe_unit" );
317+ if (p_stripe_unit) {
318+ sscanf (p_stripe_unit, " stripe_unit %lu" , &stripe_unit);
304319 } else {
305320 stripe_unit = file_layout_t::get_default ().stripe_unit ;
306321 }
307- if (strstr (buf, " stripe_count" )) {
308- sscanf (strstr (buf, " stripe_count" ), " stripe_count %lu" , &stripe_count);
322+ char *p_stripe_count = strstr (buf, " stripe_count" );
323+ if (p_stripe_count) {
324+ sscanf (p_stripe_count, " stripe_count %lu" , &stripe_count);
309325 } else {
310326 stripe_count = file_layout_t::get_default ().stripe_count ;
311327 }
312- if (strstr (buf, " object_size" )) {
313- sscanf (strstr (buf, " object_size" ), " object_size %lu" , &object_size);
328+ char *p_object_size = strstr (buf, " object_size" );
329+ if (p_object_size) {
330+ sscanf (p_object_size, " object_size %lu" , &object_size);
314331 } else {
315332 object_size = file_layout_t::get_default ().object_size ;
316333 }
0 commit comments