summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-01-14 12:42:33 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-01-14 16:12:24 -0800
commit0ca4db4996abd5e6161567575fe318663d8dd117 (patch)
tree80617e77b53fc9963d96c44e17c5f42a7ef4fbc3
parent42e0ce4adc008430e32c54a5374b7744c2c2cfe4 (diff)
Replace strcpy() calls with strncpy() or memcpy()
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--Dvi.c16
-rw-r--r--XFontName.c3
-rw-r--r--font.c8
-rw-r--r--xditview.c9
4 files changed, 22 insertions, 14 deletions
diff --git a/Dvi.c b/Dvi.c
index fea4b16..d59929d 100644
--- a/Dvi.c
+++ b/Dvi.c
@@ -190,14 +190,15 @@ WidgetClass dviWidgetClass = (WidgetClass) &dviClassRec;
static void
ClassInitialize(void)
{
- int len1 = strlen(default_font_map_1);
- int len2 = strlen(default_font_map_2);
+ size_t len1 = strlen(default_font_map_1);
+ size_t len2 = strlen(default_font_map_2);
char *dfm = XtMalloc(len1 + len2 + 1);
char *ptr = dfm;
- strcpy(ptr, default_font_map_1);
+ memcpy(ptr, default_font_map_1, len1);
ptr += len1;
- strcpy(ptr, default_font_map_2);
+ memcpy(ptr, default_font_map_2, len2);
+ ptr[len2] = '\0';
resources[0].default_addr = dfm;
XtAddConverter(XtRString, XtRBackingStore, XmuCvtStringToBackingStore,
@@ -343,7 +344,6 @@ SetValues(Widget wcurrent, Widget wrequest, Widget wnew,
DviWidget request = (DviWidget) wrequest;
DviWidget new = (DviWidget) wnew;
Boolean redisplay = FALSE;
- char *new_map;
int cur, req;
req = request->dvi.requested_page;
@@ -361,10 +361,12 @@ SetValues(Widget wcurrent, Widget wrequest, Widget wnew,
}
if (current->dvi.font_map_string != request->dvi.font_map_string) {
- new_map = XtMalloc(strlen(request->dvi.font_map_string) + 1);
+ size_t map_len = strlen (request->dvi.font_map_string) + 1;
+ char * new_map = XtMalloc (map_len);
+
if (new_map) {
redisplay = TRUE;
- strcpy(new_map, request->dvi.font_map_string);
+ memcpy(new_map, request->dvi.font_map_string, map_len);
new->dvi.font_map_string = new_map;
if (current->dvi.font_map_string)
XtFree(current->dvi.font_map_string);
diff --git a/XFontName.c b/XFontName.c
index dc4c1fa..fc5d819 100644
--- a/XFontName.c
+++ b/XFontName.c
@@ -181,6 +181,7 @@ XFormatFontName(XFontName *fontName, unsigned int fontNameAttributes,
PutHyphen();
PutString(CharSetEncoding, FontNameCharSetEncoding);
*name = '\0';
- strcpy(fontNameString, tmp);
+ strncpy (fontNameString, tmp, sizeof(XFontNameString));
+ fontNameString[sizeof(XFontNameString) - 1] = '\0';
return True;
}
diff --git a/font.c b/font.c
index 3ad54f6..36e6776 100644
--- a/font.c
+++ b/font.c
@@ -16,13 +16,15 @@
static char *
savestr(const char *s)
{
- char *n;
+ size_t len;
+ char * n;
if (!s)
return NULL;
- n = XtMalloc(strlen(s) + 1);
+ len = strlen(s) + 1;
+ n = XtMalloc (len);
if (n)
- strcpy(n, s);
+ memcpy(n, s, len);
return n;
}
diff --git a/xditview.c b/xditview.c
index 39abcea..6faa415 100644
--- a/xditview.c
+++ b/xditview.c
@@ -370,7 +370,8 @@ VisitFile(char *name, Boolean resetPage)
n = name;
XtSetArg(arg[1], XtNiconName, n);
XtSetValues(toplevel, arg, 2);
- strcpy(current_file_name, name);
+ strncpy(current_file_name, name, sizeof(current_file_name));
+ current_file_name[sizeof(current_file_name) - 1] = '\0';
current_file = new_file;
DisplayPageNumber();
}
@@ -462,8 +463,10 @@ OpenFile(Widget entry, XtPointer name, XtPointer data)
static void
OpenFileAction(Widget w, XEvent *xev, String *s, Cardinal *c)
{
- if (current_file_name[0])
- strcpy(fileBuf, current_file_name);
+ if (current_file_name[0]) {
+ strncpy(fileBuf, current_file_name, sizeof(fileBuf));
+ fileBuf[sizeof(fileBuf) - 1] = '\0';
+ }
else
fileBuf[0] = '\0';
MakePrompt(toplevel, "File to open:", NewFile, fileBuf);