Skip to content

Commit

Permalink
Merge pull request #1355 from jphickey/fix-1173-mountpt-string-append
Browse files Browse the repository at this point in the history
Fix #1173, separate append on volume_name to system_mountpt
  • Loading branch information
dzbaker committed Jan 26, 2023
2 parents a9fece5 + a67f5e2 commit 963d357
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/os/posix/src/os-impl-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "os-posix.h"
#include "os-shared-filesys.h"
#include "os-shared-idmap.h"
#include "os-shared-common.h"

/****************************************************************************************
DEFINES
Expand Down Expand Up @@ -84,6 +85,8 @@ int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token)
OS_filesys_internal_record_t *local;
struct stat stat_buf;
const char * tmpdir;
size_t mplen;
size_t vollen;
uint32 i;
enum
{
Expand Down Expand Up @@ -168,7 +171,24 @@ int32 OS_FileSysStartVolume_Impl(const OS_object_token_t *token)
return OS_FS_ERR_DRIVE_NOT_CREATED;
}

snprintf(local->system_mountpt, sizeof(local->system_mountpt), "%s/osal:%s", tmpdir, local->volume_name);
/*
* Note - performing the concatenation in a single snprintf() call seems
* to trigger a (false) pointer overlap warning, because volume_name should
* always be null terminated. To get around this, calculate the
* string size and check that it is within the expected size, and do the
* append of volume_name explicitly.
*/
mplen = snprintf(local->system_mountpt, sizeof(local->system_mountpt), "%s/osal:", tmpdir);
if (mplen < sizeof(local->system_mountpt))
{
vollen = OS_strnlen(local->volume_name, sizeof(local->volume_name));
if ((vollen + mplen) >= sizeof(local->system_mountpt))
{
vollen = sizeof(local->system_mountpt) - mplen - 1;
}
memcpy(&local->system_mountpt[mplen], local->volume_name, vollen);
local->system_mountpt[mplen + vollen] = 0;
}
}

return OS_SUCCESS;
Expand Down

0 comments on commit 963d357

Please sign in to comment.