mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-03-25 13:29:03 +02:00
cleanup (fix potential overflow in mkstemp)
Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -3039,10 +3039,9 @@ x_i_mkstemp(char *template)
|
||||
char *p;
|
||||
|
||||
char ch[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
unsigned long chlen;
|
||||
unsigned long r = rlong();
|
||||
|
||||
len = xstrxlen(template, PATH_LEN);
|
||||
chlen = xstrxlen(ch, 100);
|
||||
|
||||
/* find trailing XXXXXX */
|
||||
if (len < 6)
|
||||
@@ -3053,7 +3052,7 @@ x_i_mkstemp(char *template)
|
||||
for (i = 0; i < 100; i++) {
|
||||
|
||||
for (j = 0; j < 6; j++)
|
||||
p[j] = ch[rlong() % chlen];
|
||||
p[j] = ch[r % (sizeof(ch) - 1)];
|
||||
|
||||
fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user