* [PATCH] Add a check avoid segfault.
@ 2013-01-10 11:36 majianpeng
2013-01-10 12:18 ` Jens Axboe
0 siblings, 1 reply; 4+ messages in thread
From: majianpeng @ 2013-01-10 11:36 UTC (permalink / raw)
To: Jens Axboe; +Cc: fio
If new_size was zero or realloc failed, it would be segment fault.
So add a check.
Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
---
filesetup.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/filesetup.c b/filesetup.c
index b1ca921..324e9a6 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -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;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] Add a check avoid segfault.
2013-01-10 11:36 [PATCH] Add a check avoid segfault majianpeng
@ 2013-01-10 12:18 ` Jens Axboe
2013-01-11 0:39 ` majianpeng
0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2013-01-10 12:18 UTC (permalink / raw)
To: majianpeng; +Cc: fio
On 2013-01-10 12:36, majianpeng wrote:
> 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.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add a check avoid segfault.
2013-01-10 12:18 ` Jens Axboe
@ 2013-01-11 0:39 ` majianpeng
2013-01-11 6:55 ` Jens Axboe
0 siblings, 1 reply; 4+ messages in thread
From: majianpeng @ 2013-01-11 0:39 UTC (permalink / raw)
To: Jens Axboe; +Cc: fio
>On 2013-01-10 12:36, majianpeng wrote:
>> 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.
>
>--
>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!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add a check avoid segfault.
2013-01-11 0:39 ` majianpeng
@ 2013-01-11 6:55 ` Jens Axboe
0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2013-01-11 6:55 UTC (permalink / raw)
To: majianpeng; +Cc: fio
On 2013-01-11 01:39, majianpeng wrote:
>
>> On 2013-01-10 12:36, majianpeng wrote:
>>> 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.
>>
>> --
>> 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?
OK, you should have mentioned that. Segfaults that are easily caused by
invalid parameters being specified should of course be fixed.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-01-11 6:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-10 11:36 [PATCH] Add a check avoid segfault majianpeng
2013-01-10 12:18 ` Jens Axboe
2013-01-11 0:39 ` majianpeng
2013-01-11 6:55 ` Jens Axboe
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.