program crash after calling getline()

簡單來說

請在getline呼叫之前把lineptr  = null and n = 0這樣最安全

ssize_t getline(char **lineptr, size_t *n, FILE *stream);

如果不小心把 local var 宣告的 char buf[5] = {0}送入了getline

那 getline 有可能因為從 stream 讀到的東西長度大於5,所以 getline 會對 buf 做 realloc

但 buf 是放在 stack 上面的,因為 buf 是 local var

然後就在 stack 上面寫入了 stream 來的資訊,接著process 要拿 stack 的內容出來操作很可能就掛了,例如 stack 裡面寫了 0 ,然後 0 被dereference

Android How to make recoveryimage by mkbootfs and mkbootimg

out/host/linux-x86/bin/mkbootimg –kernel out/target/product/$TARGET_PRODUCT/kernel –ramdisk out/target/product/$TARGET_PRODUCT/ramdisk-recovery.img –cmdline \"console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 user_debug=31 msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff androidboot.selinux=permissive androidboot.hardware=$TARGET_PRODUCT androidkey.dummy=1\" –base 0x80000000 –pagesize 4096 –os_version N –os_patch_level 2016-06-01 –output out/target/product/$TARGET_PRODUCT/recovery.img –id > out/target/product/$TARGET_PRODUCT/recovery.id

out/host/linux-x86/bin/mkbootfs -d out/target/product/$TARGET_PRODUCT/system out/target/product/$TARGET_PRODUCT/recovery/root | out/host/linux-x86/bin/minigzip > out/target/product/$TARGET_PRODUCT/ramdisk-recovery.img