add '\0' terminal character

This commit is contained in:
Rehan MALAK 2018-08-13 17:46:08 +02:00
parent c5a434acea
commit 163f455fc7
2 changed files with 11 additions and 6 deletions

View File

@ -128,7 +128,8 @@ PT_THREAD(handle_output(struct httpd_state *s))
s->script = NULL;
s->script = httpd_simple_get_script(&s->filename[1]);
if(s->script == NULL) {
strncpy(s->filename, "/notfound.html", sizeof(s->filename));
strncpy(s->filename, "/notfound.html", sizeof(s->filename) - 1);
s->filename[sizeof(s->filename) - 1] = '\0';
PT_WAIT_THREAD(&s->outputpt,
send_headers(s, http_header_404));
PT_WAIT_THREAD(&s->outputpt,
@ -170,7 +171,8 @@ PT_THREAD(handle_input(struct httpd_state *s))
urlconv_tofilename(s->filename, s->inputbuf, sizeof(s->filename));
#else /* URLCONV */
if(s->inputbuf[1] == ISO_space) {
strncpy(s->filename, http_index_html, sizeof(s->filename));
strncpy(s->filename, http_index_html, sizeof(s->filename) - 1);
s->filename[sizeof(s->filename) - 1] = '\0';
} else {
s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
strncpy(s->filename, s->inputbuf, sizeof(s->filename));

View File

@ -579,8 +579,10 @@ tun_alloc(char *dev, int tap)
* IFF_NO_PI - Do not provide packet information
*/
ifr.ifr_flags = (tap ? IFF_TAP : IFF_TUN) | IFF_NO_PI;
if(*dev != 0)
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
if(*dev != 0) {
strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name) - 1);
ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
}
if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) {
close(fd);
@ -806,10 +808,11 @@ main(int argc, char **argv)
case 't':
if(strncmp("/dev/", optarg, 5) == 0) {
strncpy(tundev, optarg + 5, sizeof(tundev));
strncpy(tundev, optarg + 5, sizeof(tundev) - 1);
} else {
strncpy(tundev, optarg, sizeof(tundev));
strncpy(tundev, optarg, sizeof(tundev) - 1);
}
tundev[sizeof(tundev) - 1] = '\0';
break;
case 'a':