summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2018-07-10 14:44:35 +0000
committerMatthieu Herrb <matthieu@herrb.eu>2020-07-14 15:52:40 +0200
commit73935283dea4c05c18e2ee2d3606e450d052c60c (patch)
treeb031ab44595042c6d71811ac432cdf4cf827a37d
parent82550d3e45c4df951eb7fc669e6b2d55037cc629 (diff)
Get rid of strcpy and strncpy (they were all looking safe though)
-rw-r--r--greeter/Login.c15
-rw-r--r--greeter/greet.c6
-rw-r--r--xenodm/auth.c3
-rw-r--r--xenodm/file.c3
-rw-r--r--xenodm/resource.c9
-rw-r--r--xenodm/util.c7
6 files changed, 17 insertions, 26 deletions
diff --git a/greeter/Login.c b/greeter/Login.c
index 5692071..252ea94 100644
--- a/greeter/Login.c
+++ b/greeter/Login.c
@@ -763,7 +763,7 @@ SetPrompt (Widget ctx, int promptNum, const char *message,
return -1;
}
- strncpy(prompt, message, messageLen);
+ strlcpy(prompt, message, messageLen);
/* Make sure text prompts have at least two spaces at end */
e = messageLen;
@@ -838,12 +838,10 @@ SetValue(Widget ctx, int promptNum, char *value)
if (VALUE_TEXT(w, promptNum) == NULL)
return -1;
- if (value == NULL) {
+ if (value == NULL)
bzero(VALUE_TEXT(w, promptNum), VALUE_TEXT_MAX(w, promptNum));
- } else {
- strncpy(VALUE_TEXT(w, promptNum), value, VALUE_TEXT_MAX(w, promptNum));
- VALUE_TEXT(w, promptNum)[VALUE_TEXT_MAX(w, promptNum)] = '\0';
- }
+ else
+ strlcpy(VALUE_TEXT(w, promptNum), value, VALUE_TEXT_MAX(w, promptNum));
VALUE_SHOW_START(w, promptNum) = 0;
VALUE_SHOW_END(w, promptNum) = 0;
@@ -885,8 +883,9 @@ realizeDeleteChar (LoginWidget ctx)
} else {
EraseValue (ctx, redrawFrom, promptNum);
}
- strcpy(VALUE_TEXT(ctx, promptNum) + PROMPT_CURSOR(ctx, promptNum),
- VALUE_TEXT(ctx, promptNum) + PROMPT_CURSOR(ctx, promptNum) + 1);
+ strlcpy(VALUE_TEXT(ctx, promptNum) + PROMPT_CURSOR(ctx, promptNum),
+ VALUE_TEXT(ctx, promptNum) + PROMPT_CURSOR(ctx, promptNum) + 1,
+ VALUE_TEXT_MAX(ctx, promptNum));
DrawValue (ctx, redrawFrom, promptNum);
}
}
diff --git a/greeter/greet.c b/greeter/greet.c
index 6f17175..3802bb3 100644
--- a/greeter/greet.c
+++ b/greeter/greet.c
@@ -101,10 +101,8 @@ GreetDone (
data->name, strlen (data->passwd));
switch (status) {
case NOTIFY_OK:
- strncpy (name, data->name, sizeof(name));
- name[sizeof(name)-1] = '\0';
- strncpy (password, data->passwd, sizeof(password));
- password[sizeof(password)-1] = '\0';
+ strlcpy (name, data->name, sizeof(name));
+ strlcpy (password, data->passwd, sizeof(password));
code = 0;
done = 1;
break;
diff --git a/xenodm/auth.c b/xenodm/auth.c
index 7f022ec..2e4791a 100644
--- a/xenodm/auth.c
+++ b/xenodm/auth.c
@@ -724,8 +724,7 @@ setAuthNumber (Xauth *auth, char *name)
auth->number_length = strlen (colon);
number = malloc (auth->number_length + 1);
if (number) {
- strncpy (number, colon, auth->number_length);
- number[auth->number_length] = '\0';
+ strlcpy (number, colon, auth->number_length);
} else {
LogOutOfMem ("setAuthNumber");
auth->number_length = 0;
diff --git a/xenodm/file.c b/xenodm/file.c
index d171048..3fe73a4 100644
--- a/xenodm/file.c
+++ b/xenodm/file.c
@@ -89,8 +89,7 @@ splitIntoWords (char *s)
freeFileArgs (args);
return NULL;
}
- strncpy (args[nargs], wordStart, s - wordStart);
- args[nargs][s-wordStart] = '\0';
+ strlcpy (args[nargs], wordStart, s - wordStart);
++nargs;
args[nargs] = NULL;
}
diff --git a/xenodm/resource.c b/xenodm/resource.c
index ec61b3f..7434320 100644
--- a/xenodm/resource.c
+++ b/xenodm/resource.c
@@ -260,18 +260,15 @@ GetResource (
LogOutOfMem ("GetResource");
return;
}
- strncpy (new_string, string, len);
- new_string[len] = '\0';
+ strlcpy (new_string, string, len);
*(valuep) = new_string;
break;
case DM_INT:
- strncpy (str_buf, string, sizeof (str_buf));
- str_buf[sizeof (str_buf)-1] = '\0';
+ strlcpy (str_buf, string, sizeof (str_buf));
*((int *) valuep) = atoi (str_buf);
break;
case DM_BOOL:
- strncpy (str_buf, string, sizeof (str_buf));
- str_buf[sizeof (str_buf)-1] = '\0';
+ strlcpy (str_buf, string, sizeof (str_buf));
XmuCopyISOLatin1Lowered (str_buf, str_buf);
if (!strcmp (str_buf, "true") ||
!strcmp (str_buf, "on") ||
diff --git a/xenodm/util.c b/xenodm/util.c
index 369ce9b..a2397c8 100644
--- a/xenodm/util.c
+++ b/xenodm/util.c
@@ -136,8 +136,7 @@ putEnv(const char *string, char **env)
return NULL;
}
- strncpy(n, string,nl + 1);
- n[nl] = 0;
+ strlcpy(n, string,nl + 1);
env = setEnv(env,n,v);
free(n);
@@ -193,8 +192,8 @@ parseArgs (char **argv, const char *string)
} else {
argv = newargv;
}
- argv[i] = strncpy (save, word, string-word);
- argv[i][string-word] = '\0';
+ strlcpy (save, word, string-word);
+ argv[i] = save;
i++;
}
if (!*string)