mirror of
https://github.com/Interlisp/maiko.git
synced 2026-05-01 22:26:50 +00:00
Replaces unchecked strcpy with strlcpy.
This commit is contained in:
@@ -303,7 +303,7 @@ int FindUnixPipes(void) {
|
|||||||
/* */
|
/* */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
static int FindAvailablePty(char *Slave) {
|
static int FindAvailablePty(char *Slave, size_t SlaveLen) {
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = posix_openpt(O_RDWR);
|
res = posix_openpt(O_RDWR);
|
||||||
@@ -313,7 +313,7 @@ static int FindAvailablePty(char *Slave) {
|
|||||||
}
|
}
|
||||||
grantpt(res);
|
grantpt(res);
|
||||||
unlockpt(res);
|
unlockpt(res);
|
||||||
strcpy(Slave, ptsname(res));
|
strlcpy(Slave, ptsname(res), SlaveLen);
|
||||||
DBPRINT(("slave pty name is %s.\n", Slave));
|
DBPRINT(("slave pty name is %s.\n", Slave));
|
||||||
|
|
||||||
if (res != -1) {
|
if (res != -1) {
|
||||||
@@ -392,7 +392,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
|||||||
PipeName = build_socket_pathname(sockFD);
|
PipeName = build_socket_pathname(sockFD);
|
||||||
memset(&sock, 0, sizeof(sock));
|
memset(&sock, 0, sizeof(sock));
|
||||||
sock.sun_family = AF_UNIX;
|
sock.sun_family = AF_UNIX;
|
||||||
strcpy(sock.sun_path, PipeName);
|
strlcpy(sock.sun_path, PipeName, sizeof(sock.sun_path));
|
||||||
if (bind(sockFD, (struct sockaddr *)&sock, sizeof(struct sockaddr_un)) < 0) {
|
if (bind(sockFD, (struct sockaddr *)&sock, sizeof(struct sockaddr_un)) < 0) {
|
||||||
close(sockFD);
|
close(sockFD);
|
||||||
perror("binding sockets");
|
perror("binding sockets");
|
||||||
@@ -570,7 +570,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
|||||||
int Master;
|
int Master;
|
||||||
unsigned short len;
|
unsigned short len;
|
||||||
|
|
||||||
Master = FindAvailablePty(SlavePTY);
|
Master = FindAvailablePty(SlavePTY, sizeof(SlavePTY));
|
||||||
DBPRINT(("Fork Shell; Master PTY = %d. Slave=%c%c.\n", Master, SlavePTY[0], SlavePTY[1]));
|
DBPRINT(("Fork Shell; Master PTY = %d. Slave=%c%c.\n", Master, SlavePTY[0], SlavePTY[1]));
|
||||||
if (Master < 0) {
|
if (Master < 0) {
|
||||||
printf("Open of lisp side of PTY failed.\n");
|
printf("Open of lisp side of PTY failed.\n");
|
||||||
@@ -771,6 +771,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
|||||||
{
|
{
|
||||||
int sockFD;
|
int sockFD;
|
||||||
struct sockaddr_un sock;
|
struct sockaddr_un sock;
|
||||||
|
size_t pathsize;
|
||||||
|
|
||||||
/* First open the socket */
|
/* First open the socket */
|
||||||
sockFD = socket(AF_UNIX, SOCK_STREAM, 0);
|
sockFD = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
@@ -782,12 +783,13 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
|||||||
socket into it */
|
socket into it */
|
||||||
/* need to type-check the string here */
|
/* need to type-check the string here */
|
||||||
LispStringToCString(args[1], shcom, 2048);
|
LispStringToCString(args[1], shcom, 2048);
|
||||||
UJ[sockFD].pathname = malloc(strlen(shcom) + 1);
|
pathsize = strlen(shcom) + 1;
|
||||||
strcpy(UJ[sockFD].pathname, shcom);
|
UJ[sockFD].pathname = malloc(pathsize);
|
||||||
|
strlcpy(UJ[sockFD].pathname, shcom, pathsize);
|
||||||
/* Then bind it to the pathname, and get it listening properly */
|
/* Then bind it to the pathname, and get it listening properly */
|
||||||
|
|
||||||
sock.sun_family = AF_UNIX;
|
sock.sun_family = AF_UNIX;
|
||||||
strcpy(sock.sun_path, shcom);
|
strlcpy(sock.sun_path, shcom, sizeof(sock.sun_path));
|
||||||
if (bind(sockFD, (struct sockaddr *)&sock, sizeof(struct sockaddr_un)) < 0) {
|
if (bind(sockFD, (struct sockaddr *)&sock, sizeof(struct sockaddr_un)) < 0) {
|
||||||
close(sockFD);
|
close(sockFD);
|
||||||
free(UJ[sockFD].pathname);
|
free(UJ[sockFD].pathname);
|
||||||
|
|||||||
Reference in New Issue
Block a user