Brent Cook wrote: > > > On Oct 7, 2016, at 12:18 PM, Ted Unangst <[email protected]> wrote: > > > > Kinichiro Inoguchi wrote: > >> I think this 16 bytes string assignment has boundary issue. > >> > >> static const char sigma[16] = "expand 32-byte k"; > >> > >> I found this when I tried to build libressl-portable with MSVC on Windows. > > > > another broken compiler? the above line is perfectly valid C. > > > > Technically, that's a 17-byte string being assigned to a 16-byte character > array, including the NULL. I believe there is a way to get GCC to warn about > this as well. > > This is a simpler change:
no, because now the size of the array is 17 bytes. there's nothing wrong with initialzing a char array with a string of equal length. the nul at the end doesn't 'overflow'. it's simply not included in the array. there's even an example of this in the C standard, in the section on initialization comparing char s[] = "abc" and char t[3] = "abc". > > diff --git a/src/lib/libc/crypt/chacha_private.h > b/src/lib/libc/crypt/chacha_private.h > index b720d93..a08509c 100644 > --- a/src/lib/libc/crypt/chacha_private.h > +++ b/src/lib/libc/crypt/chacha_private.h > @@ -48,8 +48,8 @@ typedef struct > a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \ > c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); > > -static const char sigma[16] = "expand 32-byte k"; > -static const char tau[16] = "expand 16-byte k"; > +static const char sigma[] = "expand 32-byte k"; > +static const char tau[] = "expand 16-byte k"; > > static void > chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
