Replace strncpy with snprintf where necessary
This commit is contained in:
@ -682,7 +682,7 @@ int client_connection_handler(sock *client, unsigned long client_num) {
|
||||
if (pos != NULL) {
|
||||
pos = strstr(pos, "\"iso_code\":");
|
||||
pos += 12;
|
||||
strncpy(client_cc, pos, 2);
|
||||
snprintf(client_cc, sizeof(client_cc), "%s", pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ int config_load(const char *filename) {
|
||||
len = strlen(ptr);
|
||||
if (ptr[0] == '[') {
|
||||
if (ptr[len - 1] != ']') goto err;
|
||||
strncpy(tmp_config[i].name, ptr + 1, len - 2);
|
||||
snprintf(tmp_config[i].name, sizeof(tmp_config[i].name), "%.*s", (int) len - 2, ptr + 1);
|
||||
i++;
|
||||
continue;
|
||||
} else if (i == 0) {
|
||||
|
@ -125,7 +125,7 @@ int http_receive_request(sock *client, http_req *req) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
strncpy(req->method, ptr, pos1 - ptr - 1);
|
||||
snprintf(req->method, sizeof(req->method), "%.*s", (int) (pos1 - ptr - 1), ptr);
|
||||
|
||||
pos2 = memchr(pos1, ' ', rcv_len - (pos1 - buf)) + 1;
|
||||
if (pos2 == NULL) {
|
||||
|
@ -42,7 +42,7 @@
|
||||
typedef struct {
|
||||
unsigned short code;
|
||||
char type[16];
|
||||
char msg[32];
|
||||
char msg[64];
|
||||
} http_status;
|
||||
|
||||
typedef struct {
|
||||
|
@ -341,7 +341,8 @@ int rev_proxy_init(http_req *req, http_res *res, host_config *conf, sock *client
|
||||
if (res->status == NULL && status_code >= 100 && status_code <= 999) {
|
||||
custom_status->code = status_code;
|
||||
strcpy(custom_status->type, "");
|
||||
strncpy(custom_status->msg, ptr + 13, strchr(ptr, '\r') - ptr - 13);
|
||||
snprintf(custom_status->msg, sizeof(custom_status->msg), "%.*s",
|
||||
(int) (strchr(ptr, '\r') - ptr - 13), ptr + 13);
|
||||
res->status = custom_status;
|
||||
} else if (res->status == NULL) {
|
||||
res->status = http_get_status(502);
|
||||
|
@ -106,7 +106,7 @@ int url_decode(const char *str, char *dec, long *size) {
|
||||
int mime_is_compressible(const char *type) {
|
||||
if (type == NULL) return 0;
|
||||
char type_parsed[64];
|
||||
strncpy(type_parsed, type, sizeof(type_parsed) - 1);
|
||||
snprintf(type_parsed, sizeof(type_parsed), "%s", type);
|
||||
char *pos = strchr(type_parsed, ';');
|
||||
if (pos != NULL) pos[0] = 0;
|
||||
return
|
||||
|
Reference in New Issue
Block a user