mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 17:58:30 +00:00
Fix redbean date header in daemonize mode
This commit is contained in:
parent
1f2288be6e
commit
84001a246c
7 changed files with 51 additions and 49 deletions
|
@ -30,7 +30,7 @@
|
|||
* @param p is input value
|
||||
* @param n if -1 implies strlen
|
||||
* @param z if non-NULL receives output length
|
||||
* @param f can kControlC0, kControlC1 to forbid
|
||||
* @param f can kControlC0, kControlC1, kControlWs to forbid
|
||||
* @return allocated NUL-terminated buffer, or NULL w/ errno
|
||||
* @error EILSEQ means UTF-8 found we can't or won't re-encode
|
||||
* @error ENOMEM means malloc() failed
|
||||
|
@ -38,7 +38,12 @@
|
|||
char *EncodeLatin1(const char *p, size_t n, size_t *z, int f) {
|
||||
int c;
|
||||
size_t i;
|
||||
char t[256];
|
||||
char *r, *q;
|
||||
memset(t, 0, sizeof(t));
|
||||
if (f & kControlC0) memset(t + 0x00, 1, 0x20 - 0x00), t[0x7F] = 1;
|
||||
if (f & kControlC1) memset(t + 0x80, 1, 0xA0 - 0x80);
|
||||
t['\t'] = t['\r'] = t['\n'] = t['\v'] = !!(f & kControlWs);
|
||||
if (z) *z = 0;
|
||||
if (n == -1) n = p ? strlen(p) : 0;
|
||||
if ((q = r = malloc(n + 1))) {
|
||||
|
@ -51,11 +56,7 @@ char *EncodeLatin1(const char *p, size_t n, size_t *z, int f) {
|
|||
goto Invalid;
|
||||
}
|
||||
}
|
||||
if (((f & kControlC1) && 0x80 <= c && c < 0xA0) ||
|
||||
((f & kControlC0) && (c < 32 || c == 0x7F) &&
|
||||
!(c == '\t' || c == '\r' || c == '\n' || c == '\v')) ||
|
||||
((f & kControlWs) &&
|
||||
(c == '\t' || c == '\r' || c == '\n' || c == '\v'))) {
|
||||
if (t[c]) {
|
||||
goto Invalid;
|
||||
}
|
||||
*q++ = c;
|
||||
|
|
|
@ -28,7 +28,7 @@ char *EscapeFragment(const char *, size_t, size_t *);
|
|||
char *EscapeSegment(const char *, size_t, size_t *);
|
||||
char *EscapeJsStringLiteral(const char *, size_t, size_t *);
|
||||
|
||||
bool HasControlCodes(const char *, size_t, int);
|
||||
ssize_t HasControlCodes(const char *, size_t, int);
|
||||
char *Underlong(const char *, size_t, size_t *);
|
||||
char *DecodeLatin1(const char *, size_t, size_t *);
|
||||
char *EncodeLatin1(const char *, size_t, size_t *, int);
|
||||
|
|
|
@ -16,11 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/pcmpgtb.h"
|
||||
#include "libc/intrin/pmovmskb.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/bits/likely.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/thompike.h"
|
||||
#include "net/http/escape.h"
|
||||
|
@ -31,17 +27,21 @@
|
|||
* @param p is input value
|
||||
* @param n if -1 implies strlen
|
||||
* @param f can have kControlWs, kControlC0, kControlC1 to forbid
|
||||
* @return true if forbidden characters were found
|
||||
* @return index of first forbidden character or -1
|
||||
* @see VisualizeControlCodes()
|
||||
*/
|
||||
bool HasControlCodes(const char *p, size_t n, int f) {
|
||||
int c;
|
||||
ssize_t HasControlCodes(const char *p, size_t n, int f) {
|
||||
char t[256];
|
||||
wint_t x, a, b;
|
||||
size_t i, j, m;
|
||||
memset(t, 0, sizeof(t));
|
||||
if (f & kControlC0) memset(t + 0x00, 1, 0x20 - 0x00), t[0x7F] = 1;
|
||||
if (f & kControlC1) memset(t + 0x80, 1, 0xA0 - 0x80);
|
||||
t['\t'] = t['\r'] = t['\n'] = t['\v'] = !!(f & kControlWs);
|
||||
if (n == -1) n = p ? strlen(p) : 0;
|
||||
for (i = 0; i < n;) {
|
||||
x = p[i++] & 0xff;
|
||||
if (x >= 0300) {
|
||||
if (UNLIKELY(x >= 0300)) {
|
||||
a = ThomPikeByte(x);
|
||||
m = ThomPikeLen(x) - 1;
|
||||
if (i + m <= n) {
|
||||
|
@ -57,13 +57,9 @@ bool HasControlCodes(const char *p, size_t n, int f) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (((f & kControlC1) && 0x80 <= x && x < 0xA0) ||
|
||||
((f & kControlC0) && (x < 32 || x == 0x7F) &&
|
||||
!(x == '\t' || x == '\r' || x == '\n' || x == '\v')) ||
|
||||
((f & kControlWs) &&
|
||||
(x == '\t' || x == '\r' || x == '\n' || x == '\v'))) {
|
||||
return true;
|
||||
if (x < 256 && t[x]) {
|
||||
return i - 1;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/likely.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/thompike.h"
|
||||
#include "net/http/http.h"
|
||||
|
@ -45,7 +46,7 @@ bool IsAcceptablePath(const char *data, size_t size) {
|
|||
e = p + size;
|
||||
while (p < e) {
|
||||
x = *p++ & 0xff;
|
||||
if (x >= 0300) {
|
||||
if (UNLIKELY(x >= 0300)) {
|
||||
a = ThomPikeByte(x);
|
||||
n = ThomPikeLen(x) - 1;
|
||||
if (p + n <= e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue