diff options
author | Lauri Aarnio <Lauri.Aarnio@iki.fi> | 2008-08-22 13:08:43 +0300 |
---|---|---|
committer | Lauri Leukkunen <lle@rahina.org> | 2008-09-27 00:02:41 +0300 |
commit | 9ff021d9b2c6a806404eb9f1004e930d59adcd6a (patch) | |
tree | 4376aaa7da4aefa77e3b3600acb52622e24ac36b | |
parent | 4b115641c1915664ee4facc54abb5a9b8f7a0510 (diff) |
mkstemp() and mkstemp64() wrappers: Fixed filling of "template" argument
-rw-r--r-- | preload/interface.master | 19 | ||||
-rw-r--r-- | preload/libsb2.c | 44 |
2 files changed, 60 insertions, 3 deletions
diff --git a/preload/interface.master b/preload/interface.master index 3ff03e9..7f6511a 100644 --- a/preload/interface.master +++ b/preload/interface.master @@ -294,8 +294,6 @@ WRAP: int mknod(const char *pathname, mode_t mode, dev_t dev) : \ map(pathname) fail_if_readonly(pathname,-1,EROFS) WRAP: int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev) : \ map_at(dirfd,pathname) fail_if_readonly(pathname,-1,EROFS) -WRAP: int mkstemp(char *template) : map(template) fail_if_readonly(template,-1,EROFS) -WRAP: int mkstemp64(char *template) : map(template) fail_if_readonly(template,-1,EROFS) WRAP: int nftw(const char *dir, int (*fn)(const char *file, const struct stat *sb, int flag, struct FTW *s), int nopenfd, int flags) : map(dir) #ifdef HAVE_NFTW64 WRAP: int nftw64(const char *dir, int (*fn)(const char *file, const struct stat64 *sb, int flag, struct FTW *s), int nopenfd, int flags) : map(dir) @@ -405,7 +403,6 @@ WRAP: int utime(const char *filename, const struct utimbuf *buf) : \ map(filename) fail_if_readonly(filename,-1,EROFS) WRAP: int utimes(const char *filename, const struct timeval tv[2]) : \ map(filename) fail_if_readonly(filename,-1,EROFS) - -- -- 7. Socket API -- ---------- @@ -413,3 +410,19 @@ WRAP: int utimes(const char *filename, const struct timeval tv[2]) : \ GATE: int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen) GATE: int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) + +-- +-- 8. Wrappers, where argument buffer is modified +-- ------------------------------------------- +-- + +-- mkstemp() returns name of the generated filename in "template" +WRAP: int mkstemp(char *template) : \ + map(template) \ + postprocess(template) \ + fail_if_readonly(template,-1,EROFS) +WRAP: int mkstemp64(char *template) : \ + map(template) \ + postprocess(template) \ + fail_if_readonly(template,-1,EROFS) + diff --git a/preload/libsb2.c b/preload/libsb2.c index d5c4a17..2b1bc8e 100644 --- a/preload/libsb2.c +++ b/preload/libsb2.c @@ -819,3 +819,47 @@ int freopen_errno(FILE *stream) return (EROFS); } +/* mkstemp() modifies "template". This locates the part which should be + * modified, and copies the modification back from mapped buffer (which + * was modified by the real function) to callers buffer. +*/ +void mkstemp_postprocess_template(char *mapped__template, char *template) +{ + char *first_X = strchr(template, 'X'); + char *generated_id; + int mapped_len = strlen(mapped__template); + + if (!first_X) { + SB_LOG(SB_LOGLEVEL_WARNING, + "%s: orig.template did not contain X (%s,%s), won't " + "do anything", __func__, template, mapped__template); + return; + } + + /* by definition, the template should have six trailing 'X's: */ + if (strcmp(first_X, "XXXXXX")) { + SB_LOG(SB_LOGLEVEL_WARNING, + "%s: orig.template did not end with XXXXXX (%s,%s), won't " + "do anything", __func__, template, mapped__template); + return; + } + + if(mapped_len < 6) { + SB_LOG(SB_LOGLEVEL_WARNING, + "%s: mapped.template is too short (%s,%s), won't " + "do anything", __func__, template, mapped__template); + return; + } + + /* now copy last six characters from mapping result to caller's buffer*/ + strncpy(first_X, mapped__template + (mapped_len-6), 6); + + SB_LOG(SB_LOGLEVEL_DEBUG, + "%s: template set to (%s)", __func__, template); +} + +void mkstemp64_postprocess_template(char *mapped__template, char *template) +{ + mkstemp_postprocess_template(mapped__template, template); +} + |