Skip to content

Commit 63d0eed

Browse files
authored
Merge pull request #219 from saxbophone/josh/fix-minor-issues
Remove the possibility of a very unlikely security issue with sprintf()
2 parents 5f430d4 + d9ef888 commit 63d0eed

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sxbp/render_figure_to_pbm.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ static sxbp_result_t sxbp_write_pbm_header(
6666
// these are used to keep track of how many digits each is
6767
int width_string_length, height_string_length = 0;
6868
// convert width and height to a decimal string, store lengths
69-
width_string_length = sprintf(width_string, "%" PRIu32, bitmap->width);
70-
height_string_length = sprintf(height_string, "%" PRIu32, bitmap->height);
69+
width_string_length = snprintf(
70+
width_string, 11, "%" PRIu32, bitmap->width
71+
);
72+
height_string_length = snprintf(
73+
height_string, 11, "%" PRIu32, bitmap->height
74+
);
7175
/*
7276
* now that we know the length of the image dimension strings, we can now
7377
* calculate how much memory we'll have to allocate for the image buffer

0 commit comments

Comments
 (0)