diff options
author | Timo Teräs <timo.teras@iki.fi> | 2012-02-14 10:34:38 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2012-02-14 10:35:41 +0200 |
commit | 0ad00f3aa2e757e2d4650f938a737b9b7633be22 (patch) | |
tree | b3dd93947229181b446d28347b43205fe5e01458 /src | |
parent | af9e9e657a5a48dce624cf118abca85555969acf (diff) | |
download | squark-0ad00f3aa2e757e2d4650f938a737b9b7633be22.tar.bz2 squark-0ad00f3aa2e757e2d4650f938a737b9b7633be22.tar.xz |
auth-snmp: fix a crash
Can't call blob_push_formatted_username unless authentication is
successfully completed.
Diffstat (limited to 'src')
-rw-r--r-- | src/squark-auth-snmp.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/squark-auth-snmp.c b/src/squark-auth-snmp.c index e6947c4..90a908b 100644 --- a/src/squark-auth-snmp.c +++ b/src/squark-auth-snmp.c @@ -571,20 +571,25 @@ static void auth_completed(struct auth_context *auth) void *token; struct authdb_entry entry; blob_t b, uf; + int ok = 1; token = authdb_get(&adb, &auth->addr, &entry, 1); authdb_clear_entry(&entry); - b = BLOB_BUF(tmp); - blob_push(&b, BLOB_STRLEN(auth->token)); - blob_push(&b, BLOB_STR(" OK user=")); - uf_a = b.ptr; - blob_push_formatted_username(&b, username_format, auth); - uf_b = b.ptr; - blob_push(&b, BLOB_PTR_LEN("\n", 1)); - uf = BLOB_PTR_PTR(uf_a, uf_b); + if (auth_ok(auth)) { + b = BLOB_BUF(tmp); + blob_push(&b, BLOB_STRLEN(auth->token)); + blob_push(&b, BLOB_STR(" OK user=")); + uf_a = b.ptr; + blob_push_formatted_username(&b, username_format, auth); + uf_b = b.ptr; + blob_push(&b, BLOB_PTR_LEN("\n", 1)); + uf = BLOB_PTR_PTR(uf_a, uf_b); + } else { + ok = 0; + } - if (auth_ok(auth) && uf.len <= sizeof(entry.p.login_name)) { + if (ok && uf.len <= sizeof(entry.p.login_name)) { if (token != NULL && !authdb_check_login(token, &entry, uf, current_time, &adbc)) { authdb_clear_entry(&entry); |