Skip to contentSkip to conversation

Add a check avoid segfault.

PATCH In review majianpeng 2 participants 4 messages Jan 10, 2013 – Jan 11, 2013

lore
Share & tools
lore

majianpeng

author
#0 lore raw

PATCH 1/1 Add a check avoid segfault.

If new_size was zero or realloc failed, it would be segment fault. So add a check.

---
 filesetup.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
filesetup.c +4 -1
index b1ca921..324e9a6 100644
@@ -1077,8 +1077,11 @@ int add_file(struct thread_data *td, const char *fname)
 		int new_size = td->o.nr_files + 1;
 
 		dprint(FD_FILE, "resize file array to %d files\n", new_size);
-
 		td->files = realloc(td->files, new_size * sizeof(f));
+		if (td->files == NULL) {
+			log_err("fio: realloc OOM\n");
+			assert(0);
+		}
 		td->files_size = new_size;
 	}
 	td->files[cur_files] = f;
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 2 lines · majianpeng

If new_size was zero or realloc failed, it would be segment fault. So add a check.

It's a drop in the bucket, fio basically does not alloc failure checking. It'd be nice to improve on that, but you'd need a lot more than the below to get near fixing that.

Signature · 1 line
Jens Axboe
author
#2 lore raw
Quoted 12 lines · majianpeng
Quoted 2 lines

If new_size was zero or realloc failed, it would be segment fault. So add a check.

It's a drop in the bucket, fio basically does not alloc failure checking. It'd be nice to improve on that, but you'd need a lot more than the below to get near fixing that.

Signature · 1 line
Jens Axboe

yes, why did i sent this patch?Because i set nrfiles=-1,fio would be segfault. I viewed the code about judging nrfiles, the code did not check this condition. Anthor case can cause this bug if nrfiles=0xffffffff.

There are many parameters like nrfiles.So they should do same check. Maybe add those check is better rather than check alloc fail or success?

Jianpeng
Thanks!

#3 lore raw
Quoted 12 lines · majianpeng
Quoted 12 lines · majianpeng
Quoted 2 lines

If new_size was zero or realloc failed, it would be segment fault. So add a check.

It's a drop in the bucket, fio basically does not alloc failure checking. It'd be nice to improve on that, but you'd need a lot more than the below to get near fixing that.

Signature · 1 line
Jens Axboe
Quoted 6 lines

yes, why did i sent this patch?Because i set nrfiles=-1,fio would be segfault. I viewed the code about judging nrfiles, the code did not check this condition. Anthor case can cause this bug if nrfiles=0xffffffff.

There are many parameters like nrfiles.So they should do same check. Maybe add those check is better rather than check alloc fail or success?

OK, you should have mentioned that. Segfaults that are easily caused by invalid parameters being specified should of course be fixed.

Signature · 1 line
Jens Axboe