summaryrefslogtreecommitdiff
path: root/sal/osl/unx
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2011-05-16 09:18:53 +0200
committerDavid Tardon <dtardon@redhat.com>2011-05-16 15:41:26 +0200
commitb5c6345bb452c0a814aefe06bc5d215ad089397d (patch)
tree75649c827140c8aa4ceb1fb5a1f2d42f0e103b1f /sal/osl/unx
parentfbb233662f6c51be27075cffc8a910f308ca8451 (diff)
make this more robust
Diffstat (limited to 'sal/osl/unx')
-rw-r--r--sal/osl/unx/pipe.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/sal/osl/unx/pipe.c b/sal/osl/unx/pipe.c
index 38a14134d..6309e73e3 100644
--- a/sal/osl/unx/pipe.c
+++ b/sal/osl/unx/pipe.c
@@ -166,6 +166,8 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
struct sockaddr_un addr;
sal_Char name[PATH_MAX + 1];
+ size_t nNameLength = 0;
+ int bNameTooLong = 0;
oslPipe pPipe;
if (access(PIPEDEFAULTPATH, R_OK|W_OK) == 0)
@@ -176,26 +178,41 @@ oslPipe SAL_CALL osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions
{
strncpy(name, PIPEALTERNATEPATH, sizeof(name));
}
+ name[sizeof(name) - 1] = '\0'; // ensure the string is NULL-terminated
+ nNameLength = strlen(name);
+ bNameTooLong = nNameLength > sizeof(name) - 2;
+ if (!bNameTooLong)
+ {
+ size_t nRealLength = 0;
- strncat(name, "/", sizeof(name));
+ strcat(name, "/");
+ ++nNameLength;
- if (Security)
- {
- sal_Char Ident[256];
+ if (Security)
+ {
+ sal_Char Ident[256];
- Ident[0] = '\0';
+ Ident[0] = '\0';
- OSL_VERIFY(osl_psz_getUserIdent(Security, Ident, sizeof(Ident)));
+ OSL_VERIFY(osl_psz_getUserIdent(Security, Ident, sizeof(Ident)));
- snprintf(&name[strlen(name)], sizeof(name), SECPIPENAMEMASK, Ident, pszPipeName);
+ nRealLength = snprintf(&name[nNameLength], sizeof(name) - nNameLength, SECPIPENAMEMASK, Ident, pszPipeName);
+ }
+ else
+ {
+ nRealLength = snprintf(&name[nNameLength], sizeof(name) - nNameLength, PIPENAMEMASK, pszPipeName);
+ }
+
+ bNameTooLong = nRealLength > sizeof(name) - nNameLength - 1;
}
- else
+
+ if (bNameTooLong)
{
- snprintf(&name[strlen(name)], sizeof(name), PIPENAMEMASK, pszPipeName);
+ OSL_TRACE("osl_createPipe: pipe name too long");
+ return NULL;
}
-
/* alloc memory */
pPipe= __osl_createPipeImpl();