From 527611669b8b68e0b8444f6b95dacf9ba8390edc Mon Sep 17 00:00:00 2001 From: Dennis Boone Date: Sat, 11 Apr 2020 12:51:44 -0400 Subject: [PATCH] Convert strcpy() calls to strncpy(). Raise the size of the symbol name variable. --- devamlc.h | 2 +- devpnc.h | 6 +++--- em.c | 6 +++--- emdev.h | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/devamlc.h b/devamlc.h index 4dfa28f..6e7b3a7 100644 --- a/devamlc.h +++ b/devamlc.h @@ -881,7 +881,7 @@ int devamlc (int class, int func, int device) { endconnect: if (allbusy) { //warn("No free AMLC connection"); - strcpy(buf,"\r\nAll available connections are in use.\r\n\n"); + strncpy(buf,"\r\nAll available connections are in use.\r\n\n", 2047); write(fd, buf, strlen(buf)); close(fd); } else { diff --git a/devpnc.h b/devpnc.h index 0118f0f..f9ed46c 100644 --- a/devpnc.h +++ b/devpnc.h @@ -961,7 +961,7 @@ int devpnc (int class, int func, int device) { fprintf(stderr,"Line %d of ring.cfg ignored: IP address too long\n", linenum); continue; } - strcpy(temphost, p); + strncpy(temphost, p, MAXHOSTLEN); if ((p=strtok(NULL, DELIM)) == NULL) { fprintf(stderr,"Line %d of ring.cfg ignored: unique id/password missing\n", linenum); @@ -979,14 +979,14 @@ int devpnc (int class, int func, int device) { } if (i <= MAXNODEID) continue; - strcpy(ni[tempid].uid, p); + strncpy(ni[tempid].uid, p, MAXUIDLEN); /* parse the port number from the IP address */ tempport = 0; if (strcmp(temphost, "-") != 0) { if ((p=strtok(temphost, PDELIM)) != NULL) { - strcpy(ni[tempid].host, p); + strncpy(ni[tempid].host, p, MAXHOSTLEN); if ((p=strtok(NULL, PDELIM)) != NULL) { tempport = atoi(p); if (tempport < 1 || tempport > 65000) diff --git a/em.c b/em.c index 3ab4201..1c4b8eb 100644 --- a/em.c +++ b/em.c @@ -667,10 +667,10 @@ static in_addr_t bindaddr = INADDR_ANY; /* -naddr option (PnC/Ringnet) */ /* load map related data, specified with -map */ #define MAXSYMBOLS 15000 -#define MAXSYMLEN 9 +#define MAXSYMLEN 11 static int numsyms = 0; static struct { - char symname[MAXSYMLEN]; + char symname[MAXSYMLEN+1]; ea_t address; char symtype; /* o=other, c=common, e=ecb, p=proc, l=linkbase */ } mapsym[MAXSYMBOLS]; @@ -762,7 +762,7 @@ void addsym(char *sym, unsigned short seg, unsigned short word, char type) { for (ix2 = numsyms; ix2 > ix; ix2--) mapsym[ix2] = mapsym[ix2-1]; //TRACEA("%s = %o/%o\n", sym, seg, words); - strcpy(mapsym[ix+1].symname, sym); + strncpy(mapsym[ix+1].symname, sym, MAXSYMLEN); mapsym[ix+1].address = addr; mapsym[ix+1].symtype = type; numsyms++; diff --git a/emdev.h b/emdev.h index 1673cb8..3ea96d8 100644 --- a/emdev.h +++ b/emdev.h @@ -1913,11 +1913,11 @@ int devdisk (int class, int func, int device) { head = m2 & 077; u = dc[dx].usel; if (order == 2) - strcpy(ordertext,"Format"); + strncpy(ordertext,"Format", 7); else if (order == 5) - strcpy(ordertext,"Read"); + strncpy(ordertext,"Read", 7); else if (order == 6) - strcpy(ordertext,"Write"); + strncpy(ordertext,"Write", 7); TRACE(T_INST|T_DIO, "%s, head=%d, track=%d, rec=%d, recsize=%d\n", ordertext, head, track, rec, recsize); if (u == -1) { fprintf(stderr," Device '%o, order %d with no unit selected\n", device, order);