Is there a C function like sprintf in the Linux kernel?

后端 未结 5 1958
甜味超标
甜味超标 2021-01-17 08:24

Is there function like sprintf() in Linux Kernel (like printf()->printk())?

5条回答
  •  时光取名叫无心
    2021-01-17 08:43

    yes. https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/lib/vsprintf.c#n1828

    int snprintf(char *buf, size_t size, const char *fmt, ...)
    {
        va_list args;
        int i;
    
        va_start(args, fmt);
        i = vsnprintf(buf, size, fmt, args);
        va_end(args);
    
        return i;
    }
    EXPORT_SYMBOL(snprintf);
    

    sprintf() by itself is prone to buffer overflows. CERT buffer overflows, Apple, etc

提交回复
热议问题