| Tarun Batra (72) | |||||||
i have the following statement:-
i have the following declaration global:-
i want rather than printing in file i would like to print it in txt file so i did like this:-
My code fails at sprinf what should i use instead sprintf? | |||||||
|
|
|||||||
| kbw (5518) | |||
Don't use sprintf, use snprintf instead. For example:
You can write to a file with fprintf. | |||
|
Last edited on
|
|||
| Tarun Batra (72) | |
| i try'ed snprintf but its failing there too | |
|
|
|
| kbw (5518) | |
|
If you're using MSVC, it'll be _snprintf. In general, try to avoid functions that write into unbounded buffers. | |
|
|
|
| viliml (791) | |
| how about stringstream? | |
|
|
|
| KernelJay (1) | |
|
For this particular example, where the arguments to sprintf are static, the unbounded copy is probably ok but it is definitely a problem when copying user-controlled data. Check out my blog post for more information about how an sprintf can be disastrous to security: http://connect.ncircle.com/t5/VERT-Security-Research-Blog/bg-p/VERTBlog/label-name/vert%20vuln%20school:%20stack%20buffer%20overflows%20101 Part 1 deals with demonstrating how an unbounded copy can crash a program: http://connect.ncircle.com/t5/VERT-Security-Research-Blog/VERT-Vuln-School-Stack-Buffer-Overflows-101-Part-1/ba-p/5782 Part 2 explains how the stack works and leads into why the unbounded copy can corrupt crucial data on the stack: http://connect.ncircle.com/t5/VERT-Security-Research-Blog/VERT-Vuln-School-Stack-Buffer-Overflows-101-Part-2/ba-p/5796 And be sure to catch the last piece which demonstrates functional exploit code for the example buffer overflow: http://connect.ncircle.com/t5/VERT-Security-Research-Blog/VERT-Vuln-School-Stack-Buffer-Overflows-101-Part-3/ba-p/5804 | |
|
Last edited on
|
|
| iceb0und (2) | |
|
Dont use stringstream, it's out of date. You can try boost. It's amazing!! | |
|
|
|
| kbw (5518) | |
| Out of date? | |
|
|
|