diff options
author | David Tardon <dtardon@redhat.com> | 2011-05-16 09:18:53 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2011-05-16 15:41:26 +0200 |
commit | 067dd53523ecf2c5a6343c6f5b84e4074d9e9a7d (patch) | |
tree | cd7ffbdc762510bb95fc1646ba3ccf7fa62d0a29 /sal | |
parent | 0c083b43ce3bc454fac5bc3a6d1057dd4ec8806d (diff) |
make this more robust
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/pipe.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/sal/osl/unx/pipe.c b/sal/osl/unx/pipe.c index e8ab52431744..b46a8c2f7415 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(); |