From owner-freebsd-bugs@FreeBSD.ORG Sat Oct 31 20:50:01 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 521D91065676 for ; Sat, 31 Oct 2009 20:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 301CC8FC19 for ; Sat, 31 Oct 2009 20:50:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n9VKo1eE075212 for ; Sat, 31 Oct 2009 20:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n9VKo12B075211; Sat, 31 Oct 2009 20:50:01 GMT (envelope-from gnats) Resent-Date: Sat, 31 Oct 2009 20:50:01 GMT Resent-Message-Id: <200910312050.n9VKo12B075211@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 11FCD1065670 for ; Sat, 31 Oct 2009 20:41:06 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 01FB48FC0A for ; Sat, 31 Oct 2009 20:41:06 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n9VKf5YR029002 for ; Sat, 31 Oct 2009 20:41:05 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id n9VKf5e0028972; Sat, 31 Oct 2009 20:41:05 GMT (envelope-from nobody) Message-Id: <200910312041.n9VKf5e0028972@www.freebsd.org> Date: Sat, 31 Oct 2009 20:41:05 GMT From: Garrett Cooper To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/140151: Fix potential setlocale(3) in hexdump / od X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2009 20:50:01 -0000 >Number: 140151 >Category: misc >Synopsis: Fix potential setlocale(3) in hexdump / od >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Oct 31 20:50:00 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Garrett Cooper >Release: 9-CURRENT >Organization: n/a >Environment: FreeBSD optimus.zenmetsuhitotuyaneshita.net 9.0-CURRENT FreeBSD 9.0-CURRENT #0: Sun Oct 25 16:15:22 PDT 2009 gcooper@optimus.zenmetsuhitotuyaneshita.net:/usr/obj/usr/src/sys/OPTIMUS amd64 >Description: Spotted a coding issue with setlocale(3) not being checked for error when going back and reviewing the hexdump sourcecode to fix the issues that are assigned to me. Please see the attached source for the fix, as well as an improvement on determing the application in use. Execution example: [gcooper@optimus /scratch/src/head/usr.bin/hexdump]$ ln -sf ./hexdump od [gcooper@optimus /scratch/src/head/usr.bin/hexdump]$ echo "" | ./hexdump -e '"%06.6_ao " 12/1 "%3_u "' 000000 lf [gcooper@optimus /scratch/src/head/usr.bin/hexdump]$ echo "" | ./od 0000000 000012 0000001 >How-To-Repeat: >Fix: Patch attached with submission follows: Index: hexdump.c =================================================================== --- hexdump.c (revision 198534) +++ hexdump.c (working copy) @@ -50,6 +50,9 @@ #include #include #include +#include +#include +#include #include "hexdump.h" FS *fshead; /* head of format strings */ @@ -61,11 +64,12 @@ main(int argc, char *argv[]) { FS *tfs; - char *p; - (void)setlocale(LC_ALL, ""); + if (setlocale(LC_ALL, "") == NULL) { + errx(1, "Failed to set the locale to LC_ALL"); + } - if (!(p = rindex(argv[0], 'o')) || strcmp(p, "od")) + if (strncmp(basename(argv[0]), "od", strlen("od"))) newsyntax(argc, &argv); else oldsyntax(argc, &argv); >Release-Note: >Audit-Trail: >Unformatted: