M
Manju
Hi All,
I am facing a strange issue. if the string passed to
va_start()/vsnprintf() contains "%n", there is a segmentation fault. If
it's replaced with any other character, no issues. Any idea why? I
can't control %n as this is contained in the user input string.
Code Snip:
#include <stdio.h>
#include <stdarg.h>
void call_print(const char *fmt, ...)
{
va_list valist;
char tmp[1000];
va_start(valist, fmt);
printf("%s\n",fmt);
strncpy(tmp, fmt, 1000);
if (valist)
{
vsnprintf(tmp, 1000, fmt, valist);
} else
{
snprintf(tmp, 1000, fmt);
}
va_end(valist);
}
main()
{
const char *test = "testing0%x";
call_print(test);
}
Thanks in advance.
Manju
I am facing a strange issue. if the string passed to
va_start()/vsnprintf() contains "%n", there is a segmentation fault. If
it's replaced with any other character, no issues. Any idea why? I
can't control %n as this is contained in the user input string.
Code Snip:
#include <stdio.h>
#include <stdarg.h>
void call_print(const char *fmt, ...)
{
va_list valist;
char tmp[1000];
va_start(valist, fmt);
printf("%s\n",fmt);
strncpy(tmp, fmt, 1000);
if (valist)
{
vsnprintf(tmp, 1000, fmt, valist);
} else
{
snprintf(tmp, 1000, fmt);
}
va_end(valist);
}
main()
{
const char *test = "testing0%x";
call_print(test);
}
Thanks in advance.
Manju