aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2017-09-03 09:28:27 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2017-09-03 09:31:33 +0200
commit6521d8cc0aaf82d6f3d707af4c182f30b7623f74 (patch)
treeb4ee56bf87310a900e051da29a5f33ad15412b4c
parent578091f051541ffcd68fb755641fd7c45e28977c (diff)
downloadcalcurse-6521d8cc0aaf82d6f3d707af4c182f30b7623f74.tar.gz
calcurse-6521d8cc0aaf82d6f3d707af4c182f30b7623f74.zip
Use strncpy() properly in general_option_edit()
Always use strncpy() to copy strings between fixed-size buffers and pass the buffer size as maximal length parameter. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
-rw-r--r--src/custom.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/custom.c b/src/custom.c
index f83a87a..7e75e51 100644
--- a/src/custom.c
+++ b/src/custom.c
@@ -739,11 +739,11 @@ static void general_option_edit(int i)
break;
case OUTPUT_DATE_FMT:
status_mesg(output_datefmt_str, "");
- strncpy(buf, conf.output_datefmt,
- strlen(conf.output_datefmt) + 1);
+ strncpy(buf, conf.output_datefmt, BUFSIZ);
+ buf[BUFSIZ - 1] = '\0';
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- strncpy(conf.output_datefmt, buf,
- strlen(buf) + 1);
+ strncpy(conf.output_datefmt, buf, BUFSIZ);
+ conf.output_datefmt[BUFSIZ - 1] = '\0';
}
break;
case INPUT_DATE_FMT:
@@ -755,9 +755,11 @@ static void general_option_edit(int i)
break;
case DAY_HEADING_FMT:
status_mesg(output_datefmt_str, "");
- strcpy(buf, conf.day_heading);
+ strncpy(buf, conf.day_heading, BUFSIZ);
+ buf[BUFSIZ - 1] = '\0';
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- strcpy(conf.day_heading, buf);
+ strncpy(conf.day_heading, buf, BUFSIZ);
+ conf.output_datefmt[BUFSIZ - 1] = '\0';
}
break;
}