预加载自定义strchr() - ubuntu崩溃



我实现了strchr()

        global  strchr
strchr:
        cmp     byte[rdi], 0
        je      end
        cmp     [rdi], sil
        je      end
        add     rdi, 1
        jmp     strchr
end:    mov     rax, rdi
        ret

当我将其预加载为.so使用时,

export LD_PRELOAD=abs/path/to/lib.so

ubuntu 16.04崩溃。有时它完全会crahses,有时会显示Sigill(损坏的数据?)。

当我使用opensuse 4预加载它时,它起作用。

任何想法为什么?

感谢迈克尔·皮奇(Michael Petch):

strchr()不符合手册,因为找不到字符时不会返回null。

固定strchr():

global  strchr
strchr:
        cmp     [rdi], sil;first check for character (useful if user searches '')
        je      end
        cmp     byte[rdi], 0;then if it is EoS and the character is not in the string, return NULL
        je      eos
        add     rdi, 1
        jmp     strchr
eos:    mov     rax, 0
        ret
end:    mov     rax, rdi
        ret

最新更新