@@ -227,23 +227,54 @@ int Dumper::undump(const char *dump_file, bool force)
227227 char buf[HEADER_LEN];
228228 r = safe_read (fd, buf, sizeof (buf));
229229 if (r < 0 ) {
230+ derr << " Error reading " << dump_file << dendl;
231+ VOID_TEMP_FAILURE_RETRY (::close (fd));
232+ return r;
233+ } else if (r == 0 ) {
234+ // Empty file read
235+ derr << " No-op since empty journal dump file: " << dump_file << dendl;
230236 VOID_TEMP_FAILURE_RETRY (::close (fd));
231237 return r;
232238 }
233239
234240 long long unsigned start, len, write_pos, format, trimmed_pos;
235241 long unsigned stripe_unit, stripe_count, object_size;
236- sscanf (strstr (buf, " start offset" ), " start offset %llu" , &start);
237- sscanf (strstr (buf, " length" ), " length %llu" , &len);
238- sscanf (strstr (buf, " write_pos" ), " write_pos %llu" , &write_pos);
239- sscanf (strstr (buf, " format" ), " format %llu" , &format);
242+ char *phdr = strstr (buf, " start offset" );
243+ if (phdr == NULL ) {
244+ derr << " Invalid header, no 'start offset' embedded" << dendl;
245+ ::close (fd);
246+ return -EINVAL;
247+ }
248+ sscanf (phdr, " start offset %llu" , &start);
249+ phdr = strstr (buf, " length" );
250+ if (phdr == NULL ) {
251+ derr << " Invalid header, no 'length' embedded" << dendl;
252+ ::close (fd);
253+ return -EINVAL;
254+ }
255+ sscanf (phdr, " length %llu" , &len);
256+ phdr = strstr (buf, " write_pos" );
257+ if (phdr == NULL ) {
258+ derr << " Invalid header, no 'write_pos' embedded" << dendl;
259+ ::close (fd);
260+ return -EINVAL;
261+ }
262+ sscanf (phdr, " write_pos %llu" , &write_pos);
263+ phdr = strstr (buf, " format" );
264+ if (phdr == NULL ) {
265+ derr << " Invalid header, no 'format' embedded" << dendl;
266+ ::close (fd);
267+ return -EINVAL;
268+ }
269+ sscanf (phdr, " format %llu" , &format);
240270
241271 if (!force) {
242272 // need to check if fsid match onlien cluster fsid
243- if (strstr (buf, " fsid" )) {
273+ phdr = strstr (buf, " fsid" );
274+ if (phdr) {
244275 uuid_d fsid;
245276 char fsid_str[40 ];
246- sscanf (strstr (buf, " fsid " ) , " fsid %39s" , fsid_str);
277+ sscanf (phdr , " fsid %39s" , fsid_str);
247278 r = fsid.parse (fsid_str);
248279 if (!r) {
249280 derr << " Invalid fsid" << dendl;
0 commit comments