Skip to content

Commit

Permalink
rtlib: Fix fb_FileGetWstr & co to treat empty string as "illegal call"
Browse files Browse the repository at this point in the history
as done by fb_FileGetStr.
  • Loading branch information
dkl committed Sep 14, 2015
1 parent e5a2fa0 commit c31dadd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/rtlib/file_get_wstr.c
Expand Up @@ -19,22 +19,17 @@ int fb_FileGetWstrEx
if( !FB_HANDLE_USED(handle) )
return fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL );

if( (dst != NULL) && (dst_chars > 0) ) {
if (dst_chars > 1) {
/* read dst_chars - 1 chars, then add null-terminator */
size_t chars;
res = fb_FileGetDataEx( handle, pos, (void *)dst, dst_chars - 1, &chars, TRUE, TRUE );
if (res == FB_RTERROR_OK) {
dst[chars] = _LC('\0'); /* null-terminator */
if (bytesread)
*bytesread = chars * sizeof(FB_WCHAR);
}
} else {
/* room for null-terminator only */
dst[0] = _LC('\0');
res = FB_RTERROR_OK;
if( (dst != NULL) && (dst_chars > 1) ) {
/* read dst_chars - 1 chars, then add null-terminator */
size_t chars;
res = fb_FileGetDataEx( handle, pos, (void *)dst, dst_chars - 1, &chars, TRUE, TRUE );
if (res == FB_RTERROR_OK) {
dst[chars] = _LC('\0'); /* null-terminator */
if (bytesread)
*bytesread = chars * sizeof(FB_WCHAR);
}
} else {
/* no/empty destination string */
res = fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL );
}

Expand Down
1 change: 1 addition & 0 deletions src/rtlib/file_getstr.c
Expand Up @@ -22,6 +22,7 @@ int fb_FileGetStrEx( FB_FILE *handle, fb_off_t pos, void *str, ssize_t str_len,
res = fb_FileGetDataEx( handle, pos, data, len, &len, TRUE, FALSE );
data[len] = 0; /* add the null-term */
} else {
/* no/empty destination string */
res = fb_ErrorSetNum( FB_RTERROR_ILLEGALFUNCTIONCALL );
}

Expand Down

0 comments on commit c31dadd

Please sign in to comment.