diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-01-27 08:00:11 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-02-01 17:21:39 -0500 |
commit | 5ffa8c818120e35c89becd938d160235c069dd12 (patch) | |
tree | e4a1ce20a003e23618bd54f49cb4acf68aed70cd /src/core/selinux-access.c | |
parent | 294929f8916ca37d89ccb1757868d22f8068c56b (diff) |
Add a snprinf wrapper which checks that the buffer was big enough
If we scale our buffer to be wide enough for the format string, we
should expect that the calculation was correct.
char_array_0() invocations are removed, since snprintf nul-terminates
the output in any case.
A similar wrapper is used for strftime calls, but only in timedatectl.c.
Diffstat (limited to 'src/core/selinux-access.c')
-rw-r--r-- | src/core/selinux-access.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c index f6389584f7..18888747f2 100644 --- a/src/core/selinux-access.c +++ b/src/core/selinux-access.c @@ -64,16 +64,16 @@ static int audit_callback( const struct audit_info *audit = auditdata; uid_t uid = 0, login_uid = 0; gid_t gid = 0; - char login_uid_buf[DECIMAL_STR_MAX(uid_t)] = "n/a"; - char uid_buf[DECIMAL_STR_MAX(uid_t)] = "n/a"; - char gid_buf[DECIMAL_STR_MAX(gid_t)] = "n/a"; + char login_uid_buf[DECIMAL_STR_MAX(uid_t) + 1] = "n/a"; + char uid_buf[DECIMAL_STR_MAX(uid_t) + 1] = "n/a"; + char gid_buf[DECIMAL_STR_MAX(gid_t) + 1] = "n/a"; if (sd_bus_creds_get_audit_login_uid(audit->creds, &login_uid) >= 0) - snprintf(login_uid_buf, sizeof(login_uid_buf), UID_FMT, login_uid); + xsprintf(login_uid_buf, UID_FMT, login_uid); if (sd_bus_creds_get_euid(audit->creds, &uid) >= 0) - snprintf(uid_buf, sizeof(uid_buf), UID_FMT, uid); + xsprintf(uid_buf, UID_FMT, uid); if (sd_bus_creds_get_egid(audit->creds, &gid) >= 0) - snprintf(gid_buf, sizeof(gid_buf), GID_FMT, gid); + xsprintf(gid_buf, GID_FMT, gid); snprintf(msgbuf, msgbufsize, "auid=%s uid=%s gid=%s%s%s%s%s%s%s", @@ -81,8 +81,6 @@ static int audit_callback( audit->path ? " path=\"" : "", strempty(audit->path), audit->path ? "\"" : "", audit->cmdline ? " cmdline=\"" : "", strempty(audit->cmdline), audit->cmdline ? "\"" : ""); - msgbuf[msgbufsize-1] = 0; - return 0; } |