Open gy741 opened 5 years ago
If someone is interested, can contribute to this problem.
Hello, i am trying to solve this issue
I think the solution to this issue is to add exception handling for nr_tid
And i think also that if exception handling for nr_tid
is added, if (*endp != ',' && *endp != '\n')
sentence is not needed
So i tried implementing like following
while (*endp != '\n') {
int tid = strtol(tids_str, &endp, 10);
+ if(nr_tid < info->nr_tid){
tids[nr_tid++] = tid;
+ }
+ else{
+ free(tids);
+ goto out;
+ }
- if (*endp != ',' && *endp != '\n') {
- free(tids);
- goto out;
- }
tids_str = endp + 1;
}
how about it?
Please take a look at the man page of strtol
carefully and handle error cases according to the description. It seems strtol
returns 0 for the invalid output. I don't think 0 is a valid value for tid in uftrace.
Okay! thank you for your commant @namhyung . I will reflect your opinion.
Can i understand your opinion more exactly?
I understood this issue as following.
,
).tid
.So my approach is to add exception handling that work well whatever value was written to tid
.
And regarding tid
input,
In normal state, tid
should have same number of values as info->nr_tid
and Each are separated by (,
).
did i understand this correctly?
I think about the cases like the following
Normal case of tid values
eg) if info->nr-tid is 5
tid=1,2,3,4,5
Abnormal case of tid values
Less tid values
eg) if info->nr-tid is 5
tid=1,2,3,4
More tid values
eg) if info->nr-tid is 5
tid=1,2,3,4,5,6
Include character except ,
tid=a,1,2,3,4
Include Continuous ,
tid=,,,,,
So i tried implementing like below
while (*endp != '\n') {
int tid = strtol(tids_str, &endp, 10);
if(nr_tid >= info->nr_tid){ // more tib values
free(tids);
goto out;
}
if(tid){ // normal case
tids[nr_tid++] = tid;
}
else { // include character except ',' or include Continuous `,`
free(tids);
goto out;
}
tids_str = endp + 1;
}
if(nr_tid < info->nr_tid){ // less tib values
free(tids);
goto out;
}
You can also check if it's separated by ,
as in the original code.
Ah... i see
,
)
tid=1a2,3,4,5
So the reflected code looks like below
while (*endp != '\n') {
int tid = strtol(tids_str, &endp, 10);
if(nr_tid >= info->nr_tid){ // more tib values
free(tids);
goto out;
}
if(tid){ // normal case
tids[nr_tid++] = tid;
}
else { // include character except ',' or include Continuous `,`
free(tids);
goto out;
}
if (*endp != ',' && *endp != '\n') {
free(tids);
goto out;
}
tids_str = endp + 1;
}
if(nr_tid < info->nr_tid){ // less tib values
free(tids);
goto out;
}
In my opinion, i think there are to many if sentence
I also think another code
while (*endp != '\n') {
int tid = strtol(tids_str, &endp, 10);
if(tid && (nr_tid < info->nr_tid) && (*endp == ',' || *endp == '\n')){
tids[nr_tid++] = tid;
}
else {
free(tids);
goto out;
}
tids_str = endp + 1;
}
if(nr_tid < info->nr_tid){ // less tib values
free(tids);
goto out;
}
@ParkSeungHyeok Please send a PR instead of dropping code snippets here. That's much easier for us to review the code.
It'd be much better if you could add unittests for the cases you mentioned above.
@namhyung @honggyukim
I have submitted a PR for the code as a first step. Please review it when you have the chance.
And regarding unit tests: in order to learn how to add tests, would you recommend studying the code within the test
folder?
could you suggest any effective methods or resources for studying unit tests?
Hello,
I found heap-buffer overflow bug.
If there is a large amount of data(
,
) in thetaskinfo:tids
of theinfo
file, it falls into an infinite loop.https://github.com/namhyung/uftrace/blob/2d6c907dedaecb37fb73b9a42f97020842c5b6d4/cmds/info.c#L560-L569
PoC:
Crash info: