summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-11-16 17:32:52 +0100
committerAlejandro Colomar <alx@kernel.org>2023-11-16 17:32:52 +0100
commit170669bc0116c8ca53546ad5f86edb602fda4b90 (patch)
treee132a03855fea6ed8d89b983cf4eb7309cbfa344
parent7fa2c4fe05416331310da21a19eecacbb1ec7756 (diff)
lib/console.c: strdup() to avoid arbitrary buffer sizestrdup
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--lib/console.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/console.c b/lib/console.c
index b1d58c97..1b6d35e5 100644
--- a/lib/console.c
+++ b/lib/console.c
@@ -44,16 +44,21 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
*/
if (*cons != '/') {
- char *pbuf;
- STRTCPY(buf, cons);
- pbuf = &buf[0];
- while ((s = strtok (pbuf, ":")) != NULL) {
+ char *p;
+
+ p = strdup(cons);
+ if (p == NULL)
+ return def;
+
+ while ((s = strtok(p, ":")) != NULL) {
if (strcmp (s, tty) == 0) {
+ free(p);
return true;
}
- pbuf = NULL;
+ p = NULL;
}
+ free(p);
return false;
}