Skip to content

Commit 4dfbdf2

Browse files
committed
Responds to Gemini review of potential buffer overflows in quote_... fns
1 parent 51a3368 commit 4dfbdf2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/dir.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ static int quote_fname(char *file, size_t filesize)
259259
cp = file;
260260
dp = fbuf;
261261

262+
/* safety check for overflow - highly unlikely! */
263+
if (strlen(file) * 2 + 1 > sizeof(fbuf)) {
264+
return (0);
265+
}
262266
while (*cp) {
263267
switch (*cp) {
264268
case '>':
@@ -344,6 +348,10 @@ static int quote_fname_ufs(char *file, size_t filesize)
344348
cp = file;
345349
dp = fbuf;
346350

351+
/* safety check for overflow - highly unlikely! */
352+
if (strlen(file) * 2 + 1 > sizeof(fbuf)) {
353+
return (0);
354+
}
347355
while (*cp) {
348356
switch (*cp) {
349357
case '>':
@@ -419,6 +427,10 @@ static int quote_dname(char *dir, size_t dirsize)
419427
cp = dir;
420428
dp = fbuf;
421429

430+
/* safety check for overflow - highly unlikely! */
431+
if (strlen(dir) * 2 + 1 > sizeof(fbuf)) {
432+
return (0);
433+
}
422434
while (*cp) {
423435
switch (*cp) {
424436
case '>':

0 commit comments

Comments
 (0)