From patchwork Sun Jun 5 03:13:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas De Marchi X-Patchwork-Id: 9155061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B946860221 for ; Sun, 5 Jun 2016 03:14:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 915B21FF21 for ; Sun, 5 Jun 2016 03:14:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84E2128304; Sun, 5 Jun 2016 03:14:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FSL_HELO_HOME, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94D59272AA for ; Sun, 5 Jun 2016 03:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751377AbcFEDOQ (ORCPT ); Sat, 4 Jun 2016 23:14:16 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:33411 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751342AbcFEDOP (ORCPT ); Sat, 4 Jun 2016 23:14:15 -0400 Received: by mail-qk0-f196.google.com with SMTP id u63so1275814qkh.0 for ; Sat, 04 Jun 2016 20:14:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=mj7teQsykXva7rPCyY2fWwm2mwY69Pj0gZ7962yhAMk=; b=cD0eKWkW+8aXSiGwjaT4YhOMrBjCYgmYMo7gWtvDKpELi26I71MpX4gicfqUJBkiUC a2uNTmaYHV3Jjh33TjzNGTBfl1thcFQmVyT2q4TdkF1Zd4fHWW28NG4rcTU2LVztEJX5 16JfjOngge4dbmPfHO5R9dwXkOiSPQbhUESAPEpiCMzlMvEMy+seQGJOBcBlGsRKMsno gPdJu/No2bkAgyvjQUv0+DTJiWJk3JibwHZN1+Kwxb7Y2l9zbVsceHZ9n+pJjgcFcOEp 6aNA0TtFlvLJ/XwKEOt4BuKiq/RJ6asC/05lKSREY5FJmdOIBc5OZF9zi0hVMSUNRbrv 6SeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mj7teQsykXva7rPCyY2fWwm2mwY69Pj0gZ7962yhAMk=; b=l/xVKMu8uG1HA9u2rqFKz5Pkr6I9gt1cVp7sw+Lxt+JnFI7XM/KFXLXH1Xl9ITvWsC RspgaBMjKVPhQezY6YVl1K4uWnbf//Z/3gZjSvPgZzQlDZFEEyn4VKsSHpDRmQQ1vmI9 qaV+y5RCo+AAtEjHFMrk8HLbJO0pBiM8D7lNBx+QoeJuP5XbtE36CNmedfMXXfBG4eTN xBJN3+tTh8hYV+Zq93Bz6Hec9BaA3I959YXVNUKXHgBYynP9reAWv6XQYJpPVvYwlOSu QTHdQL///M5pniObIgWSIWTxJT3gXK0iLKf2ly1BtC/A6o3zNqPzcK5IUAMePRnyKexr iGGg== X-Gm-Message-State: ALyK8tK9cVA/21+b2m+ch5P3IXC61Bj0pwmc5zOx0zMaB6z0E7+7QTBb2dzlUUkExgnnRA== X-Received: by 10.55.195.193 with SMTP id r62mr9806139qkl.23.1465096454489; Sat, 04 Jun 2016 20:14:14 -0700 (PDT) Received: from ldmartin-mobl.home ([177.188.72.96]) by smtp.gmail.com with ESMTPSA id t65sm3658723qhe.23.2016.06.04.20.14.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Jun 2016 20:14:13 -0700 (PDT) From: Lucas De Marchi To: linux-modules@vger.kernel.org Cc: Michal Marek , Wouter van Kesteren , Lucas De Marchi Subject: [PATCH 1/3] libkmod-module: do not crash modinfo on 0 key id len Date: Sun, 5 Jun 2016 00:13:47 -0300 Message-Id: <1465096429-14024-1-git-send-email-lucas.de.marchi@gmail.com> X-Mailer: git-send-email 2.5.5 Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Lucas De Marchi --- libkmod/libkmod-module.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 1460c67..a19e8bc 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -2253,22 +2253,30 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_ goto list_error; count++; - /* Display the key id as 01:12:DE:AD:BE:EF:... */ - key_hex = malloc(sig_info.key_id_len * 3); - if (key_hex == NULL) - goto list_error; - for (i = 0; i < (int)sig_info.key_id_len; i++) { - sprintf(key_hex + i * 3, "%02X", - (unsigned char)sig_info.key_id[i]); - if (i < (int)sig_info.key_id_len - 1) - key_hex[i * 3 + 2] = ':'; + if (sig_info.key_id_len) { + /* Display the key id as 01:12:DE:AD:BE:EF:... */ + key_hex = malloc(sig_info.key_id_len * 3); + if (key_hex == NULL) + goto list_error; + for (i = 0; i < (int)sig_info.key_id_len; i++) { + sprintf(key_hex + i * 3, "%02X", + (unsigned char)sig_info.key_id[i]); + if (i < (int)sig_info.key_id_len - 1) + key_hex[i * 3 + 2] = ':'; + } + n = kmod_module_info_append(list, "sig_key", strlen("sig_key"), + key_hex, sig_info.key_id_len * 3 - 1); + free(key_hex); + if (n == NULL) + goto list_error; + count++; + } else { + n = kmod_module_info_append(list, "sig_key", strlen("sig_key"), + NULL, 0); + if (n == NULL) + goto list_error; + count++; } - n = kmod_module_info_append(list, "sig_key", strlen("sig_key"), - key_hex, sig_info.key_id_len * 3 - 1); - free(key_hex); - if (n == NULL) - goto list_error; - count++; n = kmod_module_info_append(list, "sig_hashalgo", strlen("sig_hashalgo"),