From 0ad00f3aa2e757e2d4650f938a737b9b7633be22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Tue, 14 Feb 2012 10:34:38 +0200 Subject: auth-snmp: fix a crash Can't call blob_push_formatted_username unless authentication is successfully completed. --- src/squark-auth-snmp.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/squark-auth-snmp.c') 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); -- cgit v1.2.3