From owner-freebsd-bugs Mon Jul 17 0:20: 5 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id A877737B8A8 for ; Mon, 17 Jul 2000 00:20:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id AAA48178; Mon, 17 Jul 2000 00:20:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: by hub.freebsd.org (Postfix, from userid 32767) id 2053837B930; Mon, 17 Jul 2000 00:17:07 -0700 (PDT) Message-Id: <20000717071707.2053837B930@hub.freebsd.org> Date: Mon, 17 Jul 2000 00:17:07 -0700 (PDT) From: chucha@jam.tario.ru To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: misc/19975: fgets() and fread() on file without reading rights leads to SEGV Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 19975 >Category: misc >Synopsis: fgets() and fread() on file without reading rights leads to SEGV >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Jul 17 00:20:01 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Pavel Chuchkalov >Release: 3.0 and 3.2 ugraded to 4.0 >Organization: - >Environment: FreeBSD 4.0-RELEASE i386 >Description: If in program file is open, and this file does not have rights to read, fgets() and fread() will cause segmentation violation. fgets() and fread() on "failed" FILE* returned by fopen() crashes program also (use the source code below but do not 'touch test') - stupid but possible programmer's error. I don't know about read() call and others. >How-To-Repeat: #include extern int errno; main() { FILE *file; char str[1024]; file = fopen("test", "r"); // fgets(str, sizeof(str), file); // fread(str, sizeof(str), 1, file); printf("feof(file) = %d, errno = %d, ferror(file) = %d\n", feof(file), errno, ferror(file)); } >Fix: I'm not competent in fixing, but I would like to be :) Please, CC: chucha@jam.tario.ru while discussing this problem, or tell me maillist (oh, how I'm tired of all of them! ;) where this problem will be discussed. Or, if I'm really wrong and my trouble is only in my mind, let me know also... Good luck! >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message