Skip to content

Commit

Permalink
Fix buffer overflow (PR#18613).
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@85415 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
kalibera committed Oct 26, 2023
1 parent 324458a commit 73e1868
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/library/graphics/src/plot3d.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1998--2018 The R Core Team
* Copyright (C) 1998--2023 The R Core Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1564,16 +1564,19 @@ static SEXP contour(SEXP x, int nx, SEXP y, int ny, SEXP z,
buffer[0] = ' ';
if (!isNull(labels)) {
int numl = length(labels);
strcpy(&buffer[1], CHAR(STRING_ELT(labels, cnum % numl)));
strncpy(&buffer[1], CHAR(STRING_ELT(labels, cnum % numl)),
sizeof(buffer) - 2);
enc = getCharCE(STRING_ELT(labels, cnum % numl));
}
else {
PROTECT(lab = allocVector(REALSXP, 1));
REAL(lab)[0] = zc;
lab = labelformat(lab);
strcpy(&buffer[1], CHAR(STRING_ELT(lab, 0))); /* ASCII */
strncpy(&buffer[1], CHAR(STRING_ELT(lab, 0)),
sizeof(buffer) - 2); /* ASCII */
UNPROTECT(1); /* lab */
}
buffer[sizeof(buffer)-2] = '\0';
buffer[strlen(buffer)+1] = '\0';
buffer[strlen(buffer)] = ' ';

Expand Down

0 comments on commit 73e1868

Please sign in to comment.