Merge pull request #651 from Rehan-MALAK/null-character

add '\0' terminal character
This commit is contained in:
George Oikonomou 2018-09-17 11:45:15 +01:00 committed by GitHub
commit b142f3d179
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 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);
@ -793,9 +795,9 @@ main(int argc, char **argv)
case 's':
if(strncmp("/dev/", optarg, 5) == 0) {
siodev = optarg + 5;
siodev = optarg + 5;
} else {
siodev = optarg;
siodev = optarg;
}
break;
@ -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':