From owner-freebsd-hackers@FreeBSD.ORG Sat Mar 21 13:59:41 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EE14738F for ; Sat, 21 Mar 2015 13:59:41 +0000 (UTC) Received: from ustc.edu.cn (email6.ustc.edu.cn [IPv6:2001:da8:d800::8]) by mx1.freebsd.org (Postfix) with ESMTP id EF3D09B5 for ; Sat, 21 Mar 2015 13:59:40 +0000 (UTC) Received: from freebsd.my.domain (unknown [58.211.218.74]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygCnVzw9eQ1VgPS+Aw--.49970S2; Sat, 21 Mar 2015 21:59:33 +0800 (CST) From: Tiwei Bie To: mjguzik@gmail.com Subject: [PATCH] Finish the task 'Validate coredump format string' Date: Sat, 21 Mar 2015 21:59:05 +0800 Message-Id: <1426946345-67889-1-git-send-email-btw@mail.ustc.edu.cn> X-Mailer: git-send-email 2.3.3 X-CM-TRANSID: LkAmygCnVzw9eQ1VgPS+Aw--.49970S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tFy5Wr15uF18ur13XFWDArb_yoW8WrWUpF yY9r98Ar4rCF43WF1fZa95AFyY9395t3yUW3y7JrnxCr1Fgry8Xr1rKryFvF1kWr92gF98 Ja15XFy7KryjvaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkYb7Iv0xC_Zr1lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8Jw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc2xSY4AK67AK6ry8MxAIw28I cxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2 IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUXVWUAwCIc40Y0x0EwIxGrwCI 42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42 IY6xAIw20EY4v20xvaj40_Zr0_Wr1UMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU0rMaUUUUUU== X-CM-SenderInfo: xewzqzxdloh3xvwfhvlgxou0/1tbiAQUPAVQhl-o8fQAAsT Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Mar 2015 13:59:42 -0000 Hi, Mateusz! I have finished the task: Validate coredump format string [1]. Following is my patch: --- sys/kern/kern_sig.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 8410d9d..52f05be 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -3099,13 +3099,38 @@ static char corefilename[MAXPATHLEN] = {"%N.core"}; static int sysctl_kern_corefile(SYSCTL_HANDLER_ARGS) { - int error; + char *format; + int i, error; + + format = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); + + sx_slock(&corefilename_lock); + strncpy(format, corefilename, MAXPATHLEN); + sx_sunlock(&corefilename_lock); + + error = sysctl_handle_string(oidp, format, MAXPATHLEN, req); + if (error != 0 || strcmp(format, corefilename) == 0) + goto out; + + for (i = 0; format[i] != '\0'; i++) { + if (format[i] == '%') { + char ch = format[++i]; + if (ch != '%' && ch != 'H' && ch != 'I' && + ch != 'N' && ch != 'P' && ch != 'U') { + error = EINVAL; + printf("Unknown format character %c in " + "corename `%s'\n", ch, format); + goto out; + } + } + } sx_xlock(&corefilename_lock); - error = sysctl_handle_string(oidp, corefilename, sizeof(corefilename), - req); + strncpy(corefilename, format, sizeof(corefilename)); sx_xunlock(&corefilename_lock); +out: + free(format, M_TEMP); return (error); } SYSCTL_PROC(_kern, OID_AUTO, corefile, CTLTYPE_STRING | CTLFLAG_RWTUN | -- 2.1.2 [1] https://wiki.freebsd.org/JuniorJobs#Validate_coredump_format_string Best regards, Tiwei Bie