Date: Sun, 25 May 2003 12:03:08 -0700 (PDT) From: Peter Wemm <peter@FreeBSD.org> To: src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org Subject: cvs commit: src/sys/kern subr_sbuf.c Message-ID: <200305251903.h4PJ38uc098642@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
peter 2003/05/25 12:03:08 PDT FreeBSD src repository Modified files: sys/kern subr_sbuf.c Log: Copy the va_list in sbuf_vprintf() before passing it to vsnprintf(), because we could fail due to a small buffer and loop and rerun. If this happens, then the vsnprintf() will have already taken the arguments off the va_list. For i386 and others, this doesn't matter because the va_list type is a passed as a copy. But on powerpc and amd64, this is fatal because the va_list is a reference to an external structure that keeps the vararg state due to the more complicated argument passing system. On amd64, arguments can be passed as follows: First 6 int/pointer type arguments go in registers, the rest go on the memory stack. Float and double are similar, except using SSE registers. long double (80 bit precision) are similar except using the x87 stack. Where the 'next argument' comes from depends on how many have been processed so far and what type it is. For amd64, gcc keeps this state somewhere that is referenced by the va_list. I found a description that showed the va_copy was required here: http://mirrors.ccs.neu.edu/cgi-bin/unixhelp/man-cgi?va_end+9 The single unix spec doesn't mention va_copy() at all. Anyway, the problem was that the sysctl kern.geom.conf* nodes would panic due to walking off the end of the va_arg lists in vsnprintf. A better fix would be to have sbuf_vprintf() use a single pass and call kvprintf() with a callback function that stored the results and grew the buffer as needed. Approved by: re (scottl) Revision Changes Path 1.24 +4 -1 src/sys/kern/subr_sbuf.c
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200305251903.h4PJ38uc098642>