mirror of
https://github.com/sheumann/hush.git
synced 2025-02-10 23:31:01 +00:00
httpd: fix buglet in hex conversion. Remove alloca NULL checks
(never happens, app just crashes if stack overflows) svlogd: cosmetic messages and style fixes
This commit is contained in:
parent
d6e81c7762
commit
72b6a65b2f
@ -163,7 +163,7 @@ enum {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t http_response_type[] = {
|
static const uint16_t http_response_type[] ALIGN2 = {
|
||||||
HTTP_OK,
|
HTTP_OK,
|
||||||
HTTP_MOVED_TEMPORARILY,
|
HTTP_MOVED_TEMPORARILY,
|
||||||
HTTP_REQUEST_TIMEOUT,
|
HTTP_REQUEST_TIMEOUT,
|
||||||
@ -287,8 +287,6 @@ struct globals {
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define STRNCASECMP(a, str) strncasecmp((a), (str), sizeof(str)-1)
|
#define STRNCASECMP(a, str) strncasecmp((a), (str), sizeof(str)-1)
|
||||||
|
|
||||||
/* Prototypes */
|
/* Prototypes */
|
||||||
@ -467,11 +465,6 @@ static void parse_conf(const char *path, int flag)
|
|||||||
|
|
||||||
if (flag == SUBDIR_PARSE || cf == NULL) {
|
if (flag == SUBDIR_PARSE || cf == NULL) {
|
||||||
cf = alloca(strlen(path) + sizeof(httpd_conf) + 2);
|
cf = alloca(strlen(path) + sizeof(httpd_conf) + 2);
|
||||||
if (cf == NULL) {
|
|
||||||
if (flag == FIRST_PARSE)
|
|
||||||
bb_error_msg_and_die(bb_msg_memory_exhausted);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sprintf((char *)cf, "%s/%s", path, httpd_conf);
|
sprintf((char *)cf, "%s/%s", path, httpd_conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,7 +547,7 @@ static void parse_conf(const char *path, int flag)
|
|||||||
/* error status code */
|
/* error status code */
|
||||||
int status = atoi(++p0);
|
int status = atoi(++p0);
|
||||||
/* c already points at the character following ':' in parse loop */
|
/* c already points at the character following ':' in parse loop */
|
||||||
// c = strchr(p0, ':'); c++;
|
/* c = strchr(p0, ':'); c++; */
|
||||||
if (status < HTTP_CONTINUE) {
|
if (status < HTTP_CONTINUE) {
|
||||||
bb_error_msg("config error '%s' in '%s'", buf, cf);
|
bb_error_msg("config error '%s' in '%s'", buf, cf);
|
||||||
continue;
|
continue;
|
||||||
@ -575,9 +568,7 @@ static void parse_conf(const char *path, int flag)
|
|||||||
if (*p0 == '/') {
|
if (*p0 == '/') {
|
||||||
/* make full path from httpd root / current_path / config_line_path */
|
/* make full path from httpd root / current_path / config_line_path */
|
||||||
cf = (flag == SUBDIR_PARSE ? path : "");
|
cf = (flag == SUBDIR_PARSE ? path : "");
|
||||||
p0 = malloc(strlen(cf) + (c - buf) + 2 + strlen(c));
|
p0 = xmalloc(strlen(cf) + (c - buf) + 2 + strlen(c));
|
||||||
if (p0 == NULL)
|
|
||||||
continue;
|
|
||||||
c[-1] = '\0';
|
c[-1] = '\0';
|
||||||
sprintf(p0, "/%s%s", cf, buf);
|
sprintf(p0, "/%s%s", cf, buf);
|
||||||
|
|
||||||
@ -694,9 +685,11 @@ static char *encodeString(const char *string)
|
|||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
while ((ch = *string++)) {
|
while ((ch = *string++)) {
|
||||||
// very simple check for what to encode
|
/* very simple check for what to encode */
|
||||||
if (isalnum(ch)) *p++ = ch;
|
if (isalnum(ch))
|
||||||
else p += sprintf(p, "&#%d;", (unsigned char) ch);
|
*p++ = ch;
|
||||||
|
else
|
||||||
|
p += sprintf(p, "&#%d;", (unsigned char) ch);
|
||||||
}
|
}
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
return out;
|
return out;
|
||||||
@ -717,18 +710,21 @@ static char *encodeString(const char *string)
|
|||||||
*/
|
*/
|
||||||
static unsigned hex_to_bin(unsigned char c)
|
static unsigned hex_to_bin(unsigned char c)
|
||||||
{
|
{
|
||||||
unsigned v = c | 0x20; /* lowercase */
|
unsigned v;
|
||||||
v = v - '0';
|
|
||||||
|
v = c - '0';
|
||||||
if (v <= 9)
|
if (v <= 9)
|
||||||
return v;
|
return v;
|
||||||
v = v + ('0' - 'a');
|
/* c | 0x20: letters to lower case, non-letters
|
||||||
|
* to (potentially different) non-letters */
|
||||||
|
v = (unsigned)(c | 0x20) - 'a';
|
||||||
if (v <= 5)
|
if (v <= 5)
|
||||||
return v + 10;
|
return v + 10;
|
||||||
return ~0;
|
return ~0;
|
||||||
}
|
}
|
||||||
/* For testing:
|
/* For testing:
|
||||||
void t(char c) { printf("'%c' %u\n", c, hex_to_bin(c)); }
|
void t(char c) { printf("'%c'(%u) %u\n", c, c, hex_to_bin(c)); }
|
||||||
int main() { t('0'); t('9'); t('A'); t('F'); t('a'); t('f');
|
int main() { t(0x10); t(0x20); t('0'); t('9'); t('A'); t('F'); t('a'); t('f');
|
||||||
t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; }
|
t('0'-1); t('9'+1); t('A'-1); t('F'+1); t('a'-1); t('f'+1); return 0; }
|
||||||
*/
|
*/
|
||||||
static char *decodeString(char *orig, int option_d)
|
static char *decodeString(char *orig, int option_d)
|
||||||
|
@ -513,22 +513,25 @@ static unsigned logdir_open(struct logdir *ld, const char *fn)
|
|||||||
/* read config */
|
/* read config */
|
||||||
i = open_read_close("config", buf, sizeof(buf));
|
i = open_read_close("config", buf, sizeof(buf));
|
||||||
if (i < 0 && errno != ENOENT)
|
if (i < 0 && errno != ENOENT)
|
||||||
bb_perror_msg(WARNING": %s/config", ld->name);
|
bb_perror_msg(WARNING"%s/config", ld->name);
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
bb_error_msg(INFO"read: %s/config", ld->name);
|
bb_error_msg(INFO"read: %s/config", ld->name);
|
||||||
s = buf;
|
s = buf;
|
||||||
while (s) {
|
while (s) {
|
||||||
np = strchr(s, '\n');
|
np = strchr(s, '\n');
|
||||||
if (np) *np++ = '\0';
|
if (np)
|
||||||
|
*np++ = '\0';
|
||||||
switch (s[0]) {
|
switch (s[0]) {
|
||||||
case '+':
|
case '+':
|
||||||
case '-':
|
case '-':
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
|
/* Add '\n'-terminated line to ld->inst */
|
||||||
while (1) {
|
while (1) {
|
||||||
int l = asprintf(&new, "%s%s\n", ld->inst?:"", s);
|
int l = asprintf(&new, "%s%s\n", ld->inst ? : "", s);
|
||||||
if (l >= 0 && new) break;
|
if (l >= 0 && new)
|
||||||
|
break;
|
||||||
pause_nomem();
|
pause_nomem();
|
||||||
}
|
}
|
||||||
free(ld->inst);
|
free(ld->inst);
|
||||||
@ -578,7 +581,8 @@ static unsigned logdir_open(struct logdir *ld, const char *fn)
|
|||||||
s = ld->inst;
|
s = ld->inst;
|
||||||
while (s) {
|
while (s) {
|
||||||
np = strchr(s, '\n');
|
np = strchr(s, '\n');
|
||||||
if (np) *np++ = '\0';
|
if (np)
|
||||||
|
*np++ = '\0';
|
||||||
s = np;
|
s = np;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -586,7 +590,7 @@ static unsigned logdir_open(struct logdir *ld, const char *fn)
|
|||||||
/* open current */
|
/* open current */
|
||||||
i = stat("current", &st);
|
i = stat("current", &st);
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
if (st.st_size && ! (st.st_mode & S_IXUSR)) {
|
if (st.st_size && !(st.st_mode & S_IXUSR)) {
|
||||||
ld->fnsave[25] = '.';
|
ld->fnsave[25] = '.';
|
||||||
ld->fnsave[26] = 'u';
|
ld->fnsave[26] = 'u';
|
||||||
ld->fnsave[27] = '\0';
|
ld->fnsave[27] = '\0';
|
||||||
@ -600,8 +604,9 @@ static unsigned logdir_open(struct logdir *ld, const char *fn)
|
|||||||
rmoldest(ld);
|
rmoldest(ld);
|
||||||
i = -1;
|
i = -1;
|
||||||
} else {
|
} else {
|
||||||
/* Be paranoid: st.st_size can be not just bigger, but WIDER! */
|
/* st.st_size can be not just bigger, but WIDER!
|
||||||
/* (bug in original svlogd. remove this comment when fixed there) */
|
* This code is safe: if st.st_size > 4GB, we select
|
||||||
|
* ld->sizemax (because it's "unsigned") */
|
||||||
ld->size = (st.st_size > ld->sizemax) ? ld->sizemax : st.st_size;
|
ld->size = (st.st_size > ld->sizemax) ? ld->sizemax : st.st_size;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -667,7 +672,7 @@ static int buffer_pread(int fd, char *s, unsigned len)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
input.fd = 0;
|
input.fd = 0;
|
||||||
input.events = POLLIN|POLLHUP|POLLERR;
|
input.events = POLLIN;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (rotateasap) {
|
if (rotateasap) {
|
||||||
@ -744,7 +749,6 @@ static int buffer_pread(int fd, char *s, unsigned len)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void sig_term_handler(int sig_no)
|
static void sig_term_handler(int sig_no)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user