Re: [PATCH] libbpf: fix str_has_sfx()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/07/2022 18:51, Alexei Starovoitov wrote:
> On Tue, Jul 19, 2022 at 10:19 AM Martin KaFai Lau <kafai@xxxxxx> wrote:
>>
>> On Tue, Jul 19, 2022 at 12:53:01PM +0300, Dan Carpenter wrote:
>>> The return from strcmp() is inverted so the it returns true instead
>>> of false and vise versa.
>>>
>>> Fixes: a1c9d61b19cb ("libbpf: Improve library identification for uprobe binary path resolution")
>>> Signed-off-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
>>> ---
>>> Spotted during review.  *cmp() functions should always have a comparison
>>> to zero.
>>>       if (strcmp(a, b) < 0) {  <-- means a < b
>>>       if (strcmp(a, b) >= 0) { <-- means a >= b
>>>       if (strcmp(a, b) != 0) { <-- means a != b
>>> etc.
>>>
>>>  tools/lib/bpf/libbpf_internal.h | 6 +++---
>>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
>>> index 9cd7829cbe41..008485296a29 100644
>>> --- a/tools/lib/bpf/libbpf_internal.h
>>> +++ b/tools/lib/bpf/libbpf_internal.h
>>> @@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
>>>       size_t str_len = strlen(str);
>>>       size_t sfx_len = strlen(sfx);
>>>
>>> -     if (sfx_len <= str_len)
>>> -             return strcmp(str + str_len - sfx_len, sfx);
>>> -     return false;
>>> +     if (sfx_len > str_len)
>>> +             return false;
>>> +     return strcmp(str + str_len - sfx_len, sfx) == 0;
>> Please tag the subject with "bpf" next time.
>>
>> Acked-by: Martin KaFai Lau <kafai@xxxxxx>
> 
> Alan,
> 
> If it was so broken how did it work earlier?
> Do we have a test for this?
> 

We have tests for automatic path determination, yes, but those
tests specify libc.so.6, so are testing the strstr(file, ".so.") 
predicate below:

	if (str_has_sfx(file, ".so") || strstr(file, ".so.")) {

Problem is, on many systems, libc.so is a GNU ld script rather
than an actual library:

cat /usr/lib64/libc.so
/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )

...so we can't rely on system library .so files actually containing
the library to instrument.

Maybe we can do something with liburandom_read.so now we have it
there; I was looking at extending the auto-path determination
to usdt too, so we could add a new test to cover this then I think.

Alan



[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux