Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 502
Alex Avatar asked Sep 04 '12 13:09

Alex


1 Answers

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

like image 119
Dmitry Zagorulkin Avatar answered Sep 20 '22 01:09

Dmitry Zagorulkin