CodeQL: apply recommendations

* Use `localtime_r` instead of `localtime`
* Use correct argument type in callback to `msgpack_packer_new`
* Address FIXME in conf.c
* Remove redundant check in websocket.c
master
Jessie Murray 4 years ago committed by Nicolas Favre-Felix
parent f9890be2c7
commit b3868d81d8

@ -237,7 +237,11 @@ conf_parse_acl(json_t *j) {
a->http_basic_auth = calloc(len, 1); a->http_basic_auth = calloc(len, 1);
base64_init_encodestate(&b64); base64_init_encodestate(&b64);
pos = base64_encode_block(plain, (int)plain_len, a->http_basic_auth, &b64); /* FIXME: check return value */ pos = base64_encode_block(plain, (int)plain_len, a->http_basic_auth, &b64);
if(!pos) { /* nothing was encoded */
fprintf(stderr, "Error: could not encode credentials as HTTP basic auth header\n");
exit(1);
}
base64_encode_blockend(a->http_basic_auth + pos, &b64); base64_encode_blockend(a->http_basic_auth + pos, &b64);
/* end string with \0 rather than \n */ /* end string with \0 rather than \n */

@ -61,7 +61,7 @@ msgpack_reply(redisAsyncContext *c, void *r, void *privdata) {
} }
static int static int
on_msgpack_write(void *data, const char *s, unsigned int sz) { on_msgpack_write(void *data, const char *s, size_t sz) {
struct msg_out *out = data; struct msg_out *out = data;

@ -51,6 +51,7 @@ slog(struct server *s, log_level level,
const char *c = ".-*#"; const char *c = ".-*#";
time_t now; time_t now;
struct tm now_tm, *lt_ret;
char time_buf[64]; char time_buf[64];
char msg[124]; char msg[124];
char line[256]; /* bounds are checked. */ char line[256]; /* bounds are checked. */
@ -66,7 +67,13 @@ slog(struct server *s, log_level level,
/* get current time */ /* get current time */
now = time(NULL); now = time(NULL);
strftime(time_buf, sizeof(time_buf), "%d %b %H:%M:%S", localtime(&now)); lt_ret = localtime_r(&now, &now_tm);
if(lt_ret) {
strftime(time_buf, sizeof(time_buf), "%d %b %H:%M:%S", lt_ret);
} else {
const char err_msg[] = "(NO TIME AVAILABLE)";
strncpy(time_buf, err_msg, sizeof(err_msg));
}
/* generate output line. */ /* generate output line. */
line_sz = snprintf(line, sizeof(line), line_sz = snprintf(line, sizeof(line),

@ -349,7 +349,7 @@ ws_reply(struct cmd *cmd, const char *p, size_t sz) {
frame[1] = sz; frame[1] = sz;
memcpy(frame + 2, p, sz); memcpy(frame + 2, p, sz);
frame_sz = sz + 2; frame_sz = sz + 2;
} else if (sz > 125 && sz <= 65536) { } else if (sz <= 65536) {
uint16_t sz16 = htons(sz); uint16_t sz16 = htons(sz);
frame[1] = 126; frame[1] = 126;
memcpy(frame + 2, &sz16, 2); memcpy(frame + 2, &sz16, 2);

Loading…
Cancel
Save