Browse Source

Fix issues found with clang analyzer

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2594 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.24
Stefan Bühler 13 years ago
parent
commit
4df22f2a32
  1. 1
      NEWS
  2. 3
      src/configparser.y
  3. 2
      src/connections.c
  4. 2
      src/fdevent_poll.c
  5. 24
      src/http_auth.c
  6. 17
      src/lemon.c
  7. 3
      src/log.c
  8. 4
      src/mod_auth.c
  9. 5
      src/mod_cgi.c
  10. 2
      src/mod_dirlisting.c
  11. 2
      src/mod_evhost.c
  12. 25
      src/mod_fastcgi.c
  13. 6
      src/mod_magnet.c
  14. 17
      src/mod_proxy.c
  15. 8
      src/mod_redirect.c
  16. 10
      src/mod_rewrite.c
  17. 4
      src/mod_rrdtool.c
  18. 29
      src/mod_scgi.c
  19. 7
      src/mod_ssi.c
  20. 4
      src/mod_status.c
  21. 2
      src/network.c
  22. 4
      src/server.c
  23. 3
      src/splaytree.c
  24. 8
      src/stat_cache.c

1
NEWS

@ -25,6 +25,7 @@ NEWS
* Change mod_expire to append Cache-Control instead of overwriting it (fixes #1197)
* Allow all comparisons for $SERVER["socket"] - only bind for "=="
* Remove strptime failed message (fixes #2031)
* Fix issues found with clang analyzer
- 1.4.23 - 2009-06-19
* Added some extra warning options in cmake and fix the resulting warnings (unused/static functions)

3
src/configparser.y

@ -72,7 +72,7 @@ data_unset *configparser_merge_data(data_unset *op1, const data_unset *op2) {
op1->free(op1);
return (data_unset *)ds;
} else {
fprintf(stderr, "data type mismatch, cannot be merge\n");
fprintf(stderr, "data type mismatch, cannot merge\n");
return NULL;
}
}
@ -193,7 +193,6 @@ varline ::= key(A) APPEND expression(B). {
du = configparser_merge_data(du, B);
if (NULL == du) {
ctx->ok = 0;
du->free(du);
}
else {
buffer_copy_string_buffer(du->key, A);

2
src/connections.c

@ -1730,7 +1730,7 @@ int connection_state_machine(server *srv, connection *con) {
case HANDLER_FINISHED:
break;
default:
log_error_write(srv, __FILE__, __LINE__, "");
log_error_write(srv, __FILE__, __LINE__, "sd", "unhandling return value", r);
break;
}
break;

2
src/fdevent_poll.c

@ -132,7 +132,7 @@ static int fdevent_poll_event_get_revent(fdevents *ev, size_t ndx) {
if (poll_r & POLLNVAL) r |= FDEVENT_NVAL;
if (poll_r & POLLPRI) r |= FDEVENT_PRI;
return ev->pollfds[ndx].revents;
return r;
}
static int fdevent_poll_event_get_fd(fdevents *ev, size_t ndx) {

24
src/http_auth.c

@ -918,15 +918,15 @@ int http_auth_digest_check(server *srv, connection *con, mod_auth_plugin_data *p
char a1[256];
char a2[256];
char *username;
char *realm;
char *nonce;
char *uri;
char *algorithm;
char *qop;
char *cnonce;
char *nc;
char *respons;
char *username = NULL;
char *realm = NULL;
char *nonce = NULL;
char *uri = NULL;
char *algorithm = NULL;
char *qop = NULL;
char *cnonce = NULL;
char *nc = NULL;
char *respons = NULL;
char *e, *c;
const char *m = NULL;
@ -967,15 +967,9 @@ int http_auth_digest_check(server *srv, connection *con, mod_auth_plugin_data *p
dkv[6].ptr = &cnonce;
dkv[7].ptr = &nc;
dkv[8].ptr = &respons;
dkv[9].ptr = NULL;
UNUSED(req);
for (i = 0; dkv[i].key; i++) {
*(dkv[i].ptr) = NULL;
}
if (p->conf.auth_backend != AUTH_BACKEND_HTDIGEST &&
p->conf.auth_backend != AUTH_BACKEND_PLAIN) {
log_error_write(srv, __FILE__, __LINE__, "s",

17
src/lemon.c

@ -39,6 +39,12 @@ extern char *getenv();
# endif
#endif
#if __GNUC__ > 2
#define NORETURN __attribute__ ((__noreturn__))
#else
#define NORETURN
#endif
/* #define PRIVATE static */
#define PRIVATE static
@ -51,7 +57,7 @@ extern char *getenv();
char *msort();
extern void *malloc();
extern void memory_error();
extern void memory_error() NORETURN;
/******** From the file "action.h" *************************************/
struct action *Action_new();
@ -59,7 +65,7 @@ struct action *Action_sort();
void Action_add();
/********* From the file "assert.h" ************************************/
void myassert();
void myassert() NORETURN;
#ifndef NDEBUG
# define assert(X) if(!(X))myassert(__FILE__,__LINE__)
#else
@ -1333,7 +1339,7 @@ void ErrorMsg(const char *filename, int lineno, const char *format, ...){
/* Report an out-of-memory condition and abort. This function
** is used mostly by the "MemoryCheck" macro in struct.h
*/
void memory_error(){
void memory_error() {
fprintf(stderr,"Out of memory. Aborting...\n");
exit(1);
}
@ -1608,7 +1614,6 @@ int k;
FILE *err;
{
int spcnt, i;
spcnt = 0;
if( argv[0] ) fprintf(err,"%s",argv[0]);
spcnt = strlen(argv[0]) + 1;
for(i=1; i<n && argv[i]; i++){
@ -2913,7 +2918,7 @@ int *lineno;
}else if( sp->destructor ){
cp = sp->destructor;
fprintf(out,"#line %d \"%s\"\n{",sp->destructorln,lemp->filename);
}else if( lemp->vardest ){
}else{
cp = lemp->vardest;
if( cp==0 ) return;
fprintf(out,"#line %d \"%s\"\n{",lemp->vardestln,lemp->filename);
@ -3042,7 +3047,7 @@ struct lemon *lemp; /* The main info structure for this parser */
int *plineno; /* Pointer to the line number */
int mhflag; /* True if generating makeheaders output */
{
int lineno = *plineno; /* The line number of the output */
int lineno; /* The line number of the output */
char **types; /* A hash table of datatypes */
int arraysize; /* Size of the "types" array */
int maxdtlength; /* Maximum length of any ".datatype" field. */

3
src/log.c

@ -62,7 +62,6 @@ int open_logfile_or_pipe(server *srv, const char* logfile) {
/* create write pipe and spawn process */
int to_log_fds[2];
pid_t pid;
if (pipe(to_log_fds)) {
log_error_write(srv, __FILE__, __LINE__, "ss", "pipe failed: ", strerror(errno));
@ -70,7 +69,7 @@ int open_logfile_or_pipe(server *srv, const char* logfile) {
}
/* fork, execve */
switch (pid = fork()) {
switch (fork()) {
case 0:
/* child */
close(STDIN_FILENO);

4
src/mod_auth.c

@ -468,7 +468,7 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) {
if (method == NULL) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"the require field is missing in:",
"the method field is missing in:",
"auth.require = ( \"...\" => ( ..., \"method\" => \"...\" ) )");
return HANDLER_ERROR;
} else {
@ -483,7 +483,7 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) {
if (realm == NULL) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"the require field is missing in:",
"the realm field is missing in:",
"auth.require = ( \"...\" => ( ..., \"realm\" => \"...\" ) )");
return HANDLER_ERROR;
}

5
src/mod_cgi.c

@ -584,12 +584,9 @@ static handler_t cgi_connection_close(server *srv, handler_ctx *hctx) {
#if 0
log_error_write(srv, __FILE__, __LINE__, "sd", "(debug) cgi exited fine, pid:", pid);
#endif
pid = 0;
return HANDLER_GO_ON;
} else {
log_error_write(srv, __FILE__, __LINE__, "sd", "cgi died, pid:", pid);
pid = 0;
return HANDLER_GO_ON;
}
}
@ -1009,7 +1006,7 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, buffer *
args[i++] = cgi_handler->ptr;
}
args[i++] = con->physical.path->ptr;
args[i++] = NULL;
args[i ] = NULL;
/* search for the last / */
if (NULL != (c = strrchr(con->physical.path->ptr, '/'))) {

2
src/mod_dirlisting.c

@ -198,7 +198,7 @@ static int parse_config_entry(server *srv, plugin_config *s, array *ca, const ch
data_unset *du;
if (NULL != (du = array_get_element(ca, option))) {
data_array *da = (data_array *)du;
data_array *da;
size_t j;
if (du->type != TYPE_ARRAY) {

2
src/mod_evhost.c

@ -213,7 +213,7 @@ static int mod_evhost_parse_host(connection *con,array *host) {
if (colon != ptr) {
ds = data_string_init();
buffer_copy_string_len(ds->key,CONST_STR_LEN("%"));
buffer_append_long(ds->key, i++);
buffer_append_long(ds->key, i /* ++ */);
buffer_copy_string_len(ds->value,ptr,colon-ptr);
array_insert_unique(host,(data_unset *)ds);

25
src/mod_fastcgi.c

@ -2792,8 +2792,11 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
* - tcp socket (do not check host->host->uses, as it may be not set which means INADDR_LOOPBACK)
* - unix socket
*/
if (!host ||
(!host->port && !host->unixsocket->used)) {
if (!host) {
log_error_write(srv, __FILE__, __LINE__, "s", "fatal error: host = NULL");
return HANDLER_ERROR;
}
if ((!host->port && !host->unixsocket->used)) {
log_error_write(srv, __FILE__, __LINE__, "sxddd",
"write-req: error",
host,
@ -3503,25 +3506,27 @@ static handler_t fcgi_check_extension(server *srv, connection *con, void *p_d, i
/* check if extension matches */
for (k = 0; k < p->conf.exts->used; k++) {
size_t ct_len; /* length of the config entry */
fcgi_extension *ext = p->conf.exts->exts[k];
extension = p->conf.exts->exts[k];
if (ext->key->used == 0) continue;
if (extension->key->used == 0) continue;
ct_len = extension->key->used - 1;
ct_len = ext->key->used - 1;
/* check _url_ in the form "/fcgi_pattern" */
if (extension->key->ptr[0] == '/') {
if (ext->key->ptr[0] == '/') {
if ((ct_len <= con->uri.path->used -1) &&
(strncmp(con->uri.path->ptr, extension->key->ptr, ct_len) == 0))
(strncmp(con->uri.path->ptr, ext->key->ptr, ct_len) == 0)) {
extension = ext;
break;
} else if ((ct_len <= s_len) && (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len))) {
}
} else if ((ct_len <= s_len) && (0 == strncmp(fn->ptr + s_len - ct_len, ext->key->ptr, ct_len))) {
/* check extension in the form ".fcg" */
extension = ext;
break;
}
}
/* extension doesn't match */
if (k == p->conf.exts->used) {
if (NULL == extension) {
return HANDLER_GO_ON;
}
}

6
src/mod_magnet.c

@ -283,17 +283,11 @@ static int magnet_atpanic(lua_State *L) {
}
static int magnet_reqhdr_get(lua_State *L) {
server *srv;
connection *con;
data_string *ds;
const char *key = luaL_checkstring(L, 2);
lua_pushstring(L, "lighty.srv");
lua_gettable(L, LUA_REGISTRYINDEX);
srv = lua_touserdata(L, -1);
lua_pop(L, 1);
lua_pushstring(L, "lighty.con");
lua_gettable(L, LUA_REGISTRYINDEX);
con = lua_touserdata(L, -1);

17
src/mod_proxy.c

@ -1107,19 +1107,20 @@ static handler_t mod_proxy_check_extension(server *srv, connection *con, void *p
/* check if extension matches */
for (k = 0; k < p->conf.extensions->used; k++) {
data_array *ext = NULL;
size_t ct_len;
extension = (data_array *)p->conf.extensions->data[k];
ext = (data_array *)p->conf.extensions->data[k];
if (extension->key->used == 0) continue;
if (ext->key->used == 0) continue;
ct_len = extension->key->used - 1;
ct_len = ext->key->used - 1;
if (s_len < ct_len) continue;
/* check extension in the form "/proxy_pattern" */
if (*(extension->key->ptr) == '/') {
if (strncmp(fn->ptr, extension->key->ptr, ct_len) == 0) {
if (*(ext->key->ptr) == '/') {
if (strncmp(fn->ptr, ext->key->ptr, ct_len) == 0) {
if (s_len > ct_len + 1) {
char *pi_offset;
@ -1127,15 +1128,17 @@ static handler_t mod_proxy_check_extension(server *srv, connection *con, void *p
path_info_offset = pi_offset - fn->ptr;
}
}
extension = ext;
break;
}
} else if (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len)) {
} else if (0 == strncmp(fn->ptr + s_len - ct_len, ext->key->ptr, ct_len)) {
/* check extension in the form ".fcg" */
extension = ext;
break;
}
}
if (k == p->conf.extensions->used) {
if (NULL == extension) {
return HANDLER_GO_ON;
}

8
src/mod_redirect.c

@ -203,7 +203,7 @@ static handler_t mod_redirect_uri_handler(server *srv, connection *con, void *p_
}
} else {
const char **list;
size_t start, end;
size_t start;
size_t k;
/* it matched */
@ -213,16 +213,14 @@ static handler_t mod_redirect_uri_handler(server *srv, connection *con, void *p_
buffer_reset(p->location);
start = 0; end = pattern_len;
start = 0;
for (k = 0; k < pattern_len; k++) {
if (pattern[k] == '$' || pattern[k] == '%') {
/* got one */
size_t num = pattern[k + 1] - '0';
end = k;
buffer_append_string_len(p->location, pattern + start, end - start);
buffer_append_string_len(p->location, pattern + start, k - start);
if (!isdigit((unsigned char)pattern[k + 1])) {
/* enable escape: "%%" => "%", "%a" => "%a", "$$" => "$" */

10
src/mod_rewrite.c

@ -176,7 +176,7 @@ static int parse_config_entry(server *srv, plugin_config *s, array *ca, const ch
data_unset *du;
if (NULL != (du = array_get_element(ca, option))) {
data_array *da = (data_array *)du;
data_array *da;
size_t j;
if (du->type != TYPE_ARRAY) {
@ -373,7 +373,7 @@ URIHANDLER_FUNC(mod_rewrite_uri_handler) {
}
} else {
const char **list;
size_t start, end;
size_t start;
size_t k;
/* it matched */
@ -383,16 +383,14 @@ URIHANDLER_FUNC(mod_rewrite_uri_handler) {
buffer_reset(con->request.uri);
start = 0; end = pattern_len;
start = 0;
for (k = 0; k < pattern_len; k++) {
if (pattern[k] == '$' || pattern[k] == '%') {
/* got one */
size_t num = pattern[k + 1] - '0';
end = k;
buffer_append_string_len(con->request.uri, pattern + start, end - start);
buffer_append_string_len(con->request.uri, pattern + start, k - start);
if (!isdigit((unsigned char)pattern[k + 1])) {
/* enable escape: "%%" => "%", "%a" => "%a", "$$" => "$" */

4
src/mod_rrdtool.c

@ -139,7 +139,7 @@ static int mod_rrd_create_pipe(server *srv, plugin_data *p) {
args[i++] = p->conf.path_rrdtool_bin->ptr;
args[i++] = dash;
args[i++] = NULL;
args[i ] = NULL;
/* we don't need the client socket */
for (i = 3; i < 256; i++) {
@ -266,7 +266,7 @@ static int mod_rrdtool_create_rrd(server *srv, plugin_data *p, plugin_config *s)
"RRA:MIN:0.5:24:775 "
"RRA:MIN:0.5:288:797\n"));
if (-1 == (r = safe_write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) {
if (-1 == (safe_write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"rrdtool-write: failed", strerror(errno));

29
src/mod_scgi.c

@ -785,10 +785,8 @@ static int scgi_spawn_connection(server *srv,
env.used = 0;
if (scgi_fd != 0) {
close(0);
dup2(scgi_fd, 0);
close(scgi_fd);
scgi_fd = 0;
}
/* we don't need the client socket */
@ -2176,8 +2174,11 @@ static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
int ret;
/* sanity check */
if (!host ||
((!host->host->used || !host->port) && !host->unixsocket->used)) {
if (!host) {
log_error_write(srv, __FILE__, __LINE__, "s", "fatal error: host = NULL");
return HANDLER_ERROR;
}
if (((!host->host->used || !host->port) && !host->unixsocket->used)) {
log_error_write(srv, __FILE__, __LINE__, "sxddd",
"write-req: error",
host,
@ -2482,12 +2483,10 @@ SUBREQUEST_FUNC(mod_scgi_handle_subrequest) {
}
static handler_t scgi_connection_close(server *srv, handler_ctx *hctx) {
plugin_data *p;
connection *con;
if (NULL == hctx) return HANDLER_GO_ON;
p = hctx->plugin_data;
con = hctx->remote_conn;
log_error_write(srv, __FILE__, __LINE__, "ssdsd",
@ -2737,27 +2736,29 @@ static handler_t scgi_check_extension(server *srv, connection *con, void *p_d, i
/* check if extension matches */
for (k = 0; k < p->conf.exts->used; k++) {
size_t ct_len;
scgi_extension *ext = p->conf.exts->exts[k];
extension = p->conf.exts->exts[k];
if (extension->key->used == 0) continue;
if (ext->key->used == 0) continue;
ct_len = extension->key->used - 1;
ct_len = ext->key->used - 1;
if (s_len < ct_len) continue;
/* check extension in the form "/scgi_pattern" */
if (*(extension->key->ptr) == '/') {
if (strncmp(fn->ptr, extension->key->ptr, ct_len) == 0)
if (*(ext->key->ptr) == '/') {
if (strncmp(fn->ptr, ext->key->ptr, ct_len) == 0) {
extension = ext;
break;
} else if (0 == strncmp(fn->ptr + s_len - ct_len, extension->key->ptr, ct_len)) {
}
} else if (0 == strncmp(fn->ptr + s_len - ct_len, ext->key->ptr, ct_len)) {
/* check extension in the form ".fcg" */
extension = ext;
break;
}
}
/* extension doesn't match */
if (k == p->conf.exts->used) {
if (NULL == extension) {
return HANDLER_GO_ON;
}

7
src/mod_ssi.c

@ -362,7 +362,8 @@ static int process_ssi_stmt(server *srv, connection *con, plugin_data *p,
switch(ssicmd) {
case SSI_ECHO: {
/* echo */
int var = 0, enc = 0;
int var = 0;
/* int enc = 0; */
const char *var_val = NULL;
stat_cache_entry *sce = NULL;
@ -381,6 +382,7 @@ static int process_ssi_stmt(server *srv, connection *con, plugin_data *p,
{ NULL, SSI_ECHO_UNSET }
};
/*
struct {
const char *var;
enum { SSI_ENC_UNSET, SSI_ENC_URL, SSI_ENC_NONE, SSI_ENC_ENTITY } type;
@ -391,6 +393,7 @@ static int process_ssi_stmt(server *srv, connection *con, plugin_data *p,
{ NULL, SSI_ENC_UNSET }
};
*/
for (i = 2; i < n; i += 2) {
if (0 == strcmp(l[i], "var")) {
@ -405,6 +408,7 @@ static int process_ssi_stmt(server *srv, connection *con, plugin_data *p,
}
}
} else if (0 == strcmp(l[i], "encoding")) {
/*
int j;
for (j = 0; encvars[j].var; j++) {
@ -413,6 +417,7 @@ static int process_ssi_stmt(server *srv, connection *con, plugin_data *p,
break;
}
}
*/
} else {
log_error_write(srv, __FILE__, __LINE__, "sss",
"ssi: unknow attribute for ",

4
src/mod_status.c

@ -621,10 +621,10 @@ static handler_t mod_status_handle_server_status_text(server *srv, connection *c
}
static handler_t mod_status_handle_server_statistics(server *srv, connection *con, void *p_d) {
plugin_data *p = p_d;
buffer *b = p->module_list;
buffer *b;
size_t i;
array *st = srv->status;
UNUSED(p_d);
if (0 == st->used) {
/* we have nothing to send */

2
src/network.c

@ -285,8 +285,6 @@ static int network_server_init(server *srv, buffer *host_token, specific_config
break;
default:
addr_len = 0;
return -1;
}

4
src/server.c

@ -782,7 +782,7 @@ int main (int argc, char **argv) {
* Change group before chroot, when we have access
* to /etc/group
* */
if (srv->srvconf.groupname->used) {
if (NULL != grp) {
setgid(grp->gr_gid);
setgroups(0, NULL);
if (srv->srvconf.username->used) {
@ -806,7 +806,7 @@ int main (int argc, char **argv) {
#endif
#ifdef HAVE_PWD_H
/* drop root privs */
if (srv->srvconf.username->used) {
if (NULL != pwd) {
setuid(pwd->pw_uid);
}
#endif

3
src/splaytree.c

@ -61,12 +61,11 @@
* size fields are maintained */
splay_tree * splaytree_splay (splay_tree *t, int i) {
splay_tree N, *l, *r, *y;
int comp, root_size, l_size, r_size;
int comp, l_size, r_size;
if (t == NULL) return t;
N.left = N.right = NULL;
l = r = &N;
root_size = node_size(t);
l_size = r_size = 0;
for (;;) {

8
src/stat_cache.c

@ -503,11 +503,9 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
}
if (NULL == sce) {
int osize = 0;
if (sc->files) {
osize = sc->files->size;
}
#ifdef DEBUG_STAT_CACHE
int osize = splaytree_size(sc->files);
#endif
sce = stat_cache_entry_init();
buffer_copy_string_buffer(sce->name, name);

Loading…
Cancel
Save