Fix fmemopen(3) fseeko(3) overflow detection.

This commit is contained in:
Jonas 'Sortie' Termansen 2023-03-17 00:48:16 +01:00
parent 03ee6d4d89
commit e9877d8080
1 changed files with 2 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2015, 2023 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -114,7 +114,7 @@ static off_t fmemopen_seek(void* state_ptr, off_t offset, int whence)
case SEEK_END: base = (off_t) state->buffer_used; break;
default: return errno = EINVAL, -1;
}
if ( offset < -base || base - (off_t) state->buffer_size < offset )
if ( offset < -base || (off_t) state->buffer_size - base < offset )
return errno = EOVERFLOW, -1;
return (off_t) (state->buffer_offset = (size_t) (base + offset));
}