| Age | Commit message (Collapse) | Author | Files | Lines |
|
This function is identical to nxt_ustr2str(), except that it takes
a nxt_str_t structure as input, instead of a 'u_char *' and a size.
The documentation of the function:
/*
* SYNOPSIS
* void nxt_usts2str(char dst[restrict .src->length+1],
* const nxt_str_t *restrict src);
*
* ARGUMENTS
* dst Pointer to the first byte of the destination buffer.
* src Pointer to the source Unterminated STring Structure.
*
* DESCRIPTION
* Copy a string from the source nxt_str_t, which may be
* not-NUL-terminated, into a NUL-terminated string in the
* destination buffer.
*
* CAVEATS
* If the destination buffer is not wider than the source buffer
* at least by 1 byte, the behavior is undefined.
*
* EXAMPLES
* nxt_str_t src = nxt_string("0123456789");
* char dst[src.length + 1];
*
* nxt_usts2str(dst, &src);
*
* SEE ALSO
* ustr2str(3), strlcpy(3), strscpy(9)
*/
Suggested-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
|
|
This function makes it easy to transform a fixed-width buffer
(which is how we represent strings in Unit most of the time) into
a proper C string (NUL-terminated). We need to do this when
interfacing libraries or the kernel, where most APIs expect
NUL-terminated strings.
The implementation is similar to strncpy_s(3), but avoids the
unnecessary runtime checks. It's better to wrap the function in a
macro and do as many static_assert(3)s as one considers necessary;
in fact, if in the future C allows backwards VLA syntax, static
analysis could be better than those static_assert(3)s.
We use char for NUL-terminated strings, and u_char for the
*u*nterminated strings.
The documentation for the function:
/*
* SYNOPSIS
* void ustr2str(char dst[restrict .n+1],
* const u_char src[restrict .n],
* size_t n);
*
* ARGUMENTS
* dst Pointer to the first byte of the destination buffer.
* src Pointer to the first byte of the source string.
* n Size of 'src'.
*
* DESCRIPTION
* Copy a string from the fixed-width source string, which may be
* not-NUL-terminated, into a NUL-terminated string in the
* destination buffer.
*
* CAVEATS
* If the destination buffer is not wider than the source buffer
* at least by 1 byte, the behavior is undefined.
*
* Use of this function normally indicates a problem in the design
* of the strings, since normally it's better to guarantee that all
* strings are properly terminated. The main use for this function
* is to interface with some standard buffers, such as those
* defined in utmp(7), which for historical reasons are not
* guaranteed to be terminated.
*
* EXAMPLES
* u_char src[10] = "0123456789"; // not NUL-terminated
* char dst[sizeof(src) + 1];
*
* static_assert(lengthof(src) < lengthof(dst))
* ustr2str(dst, src, lengthof(src));
*
* SEE ALSO
* nxt_sts2str(3), strlcpy(3), strscpy(9)
*/
Cc: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
|
|
The casts are unnecessary, since memcmp(3)'s arguments are 'void *'.
It might have been necessary in the times of K&R, where 'void *' didn't
exist. Nowadays, it's unnecessary, and _very_ unsafe, since casts can
hide all classes of bugs by silencing most compiler warnings.
The changes from nxt_memcmp() to memcmp(3) were scripted:
$ find src/ -type f \
| grep '\.[ch]$' \
| xargs sed -i 's/nxt_memcmp/memcmp/'
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
|
|
As was pointed out by the cppcheck[0] static code analysis utility we
can mark numerous function parameters as 'const'. This acts as a hint to
the compiler about our intentions and the compiler will tell us when we
deviate from them.
[0]: https://cppcheck.sourceforge.io/
|
|
Compared to the previous implementation based on OpenSSL, the new implementation
has these advantages:
1. Strict and reliable detection of invalid strings, including strings with
less than 4 bytes of garbage at the end;
2. Allows to use Base64 strings without '=' padding.
|
|
|
|
|
|
|
|
Now '>', '<', '"', '^', '\', '}', '|', '{', and '`' are also escaped.
|
|
|
|
|
|
Now URI encoding can be used to escape "/" in the request path:
GET /config/listeners/unix:%2Fpath%2Fto%2Fsocket/
|
|
|
|
|
|
|
|
|
|
|
|
Configuration and building example:
./configure
./configure python
./configure php
./configure go
make all
or
./configure
make nginext
./configure python
make python
./configure php
make php
./configure go
make go
Modules configuration options and building examples:
./configure python --module=python2 --config=python2.7-config
make python2
./configure php --module=php7 --config=php7.0-config
--lib-path=/usr/local/php7.0
make php7
./configure go --go=go1.6 --go-path=${HOME}/go1.6
make go1.6
|
|
|
|
|
|
|
|
|
|
|