From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#16717: Dumping: Can't update subspace record Date: Mon, 10 Feb 2014 10:40:03 -0800 Organization: UCLA Computer Science Department Message-ID: <52F91D03.4040806@cs.ucla.edu> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060304030608090303030201" X-Trace: ger.gmane.org 1392058776 21658 80.91.229.3 (10 Feb 2014 18:59:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Feb 2014 18:59:36 +0000 (UTC) To: Klaus.Zeitler@alcatel-lucent.com, 16717@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Feb 10 19:59:43 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WCw4z-0005vt-4w for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Feb 2014 19:59:41 +0100 Original-Received: from localhost ([::1]:57592 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCw4y-0007Fg-Rv for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Feb 2014 13:59:40 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCvn4-0000qP-Bx for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2014 13:41:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WCvmw-0007Cg-Tm for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2014 13:41:10 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:33822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCvmw-0007CZ-OZ for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2014 13:41:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WCvmw-0000Cd-Fz for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2014 13:41:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 10 Feb 2014 18:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16717 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 16717-submit@debbugs.gnu.org id=B16717.1392057612676 (code B ref 16717); Mon, 10 Feb 2014 18:41:02 +0000 Original-Received: (at 16717) by debbugs.gnu.org; 10 Feb 2014 18:40:12 +0000 Original-Received: from localhost ([127.0.0.1]:41710 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCvm7-0000Ap-IJ for submit@debbugs.gnu.org; Mon, 10 Feb 2014 13:40:12 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:60218) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WCvm5-0000Ac-DP for 16717@debbugs.gnu.org; Mon, 10 Feb 2014 13:40:10 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id E5F1EA60007; Mon, 10 Feb 2014 10:40:03 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4+Moiq0FyDVE; Mon, 10 Feb 2014 10:40:03 -0800 (PST) Original-Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 354EBA60005; Mon, 10 Feb 2014 10:40:03 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:85299 Archived-At: This is a multi-part message in MIME format. --------------060304030608090303030201 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Could you please try the attached patch? I can't easily test under HP-UX, so you may have to tweak it. Thanks. --------------060304030608090303030201 Content-Type: text/x-patch; name="hp.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="hp.diff" diff -pru emacs-24.3/src/unexhp9k800.c emacs-24.3-hp/src/unexhp9k800.c --- emacs-24.3/src/unexhp9k800.c 2012-04-13 18:33:59.000000000 -0700 +++ emacs-24.3-hp/src/unexhp9k800.c 2014-02-10 10:26:09.323174656 -0800 @@ -73,6 +73,22 @@ run_time_remap (char *ignored) #define roundup(x,n) (((x) + ((n) - 1)) & ~((n) - 1)) /* n is power of 2 */ #define min(x,y) (((x) < (y)) ? (x) : (y)) +/* Report a fatal error and exit. */ +static _Noreturn void +unexec_error (char const *msg) +{ + perror (msg); + exit (1); +} + +/* Do an lseek and check the result. */ +static void +check_lseek (int fd, off_t offset, int whence) +{ + if (lseek (fd, offset, whence) < 0) + unexec_error ("Cannot lseek"); +} + /* Save current data space in the file, update header. */ static void @@ -81,7 +97,7 @@ save_data_space (int file, struct header { /* Write the entire data space out to the file */ if (write (file, auxhdr->exec_dmem, size) != size) - { perror ("Can't save new data space"); exit (1); } + unexec_error ("Can't save new data space"); /* Update the header to reflect the new data size */ auxhdr->exec_dsize = size; @@ -114,20 +130,21 @@ update_file_ptrs (int file, struct heade update (auxhdr->exec_dfile); /* Do for each subspace dictionary entry */ - lseek (file, hdr->subspace_location, 0); + check_lseek (file, hdr->subspace_location, 0); for (i = 0; i < hdr->subspace_total; i++) { - if (read (file, &subspace, sizeof (subspace)) != sizeof (subspace)) - { perror ("Can't read subspace record"); exit (1); } + ptrdiff_t subspace_size = sizeof subspace; + if (read (file, &subspace, subspace_size) != subspace_size) + unexec_error ("Can't read subspace record"); /* If subspace has a file location, update it */ if (subspace.initialization_length > 0 && subspace.file_loc_init_value > location) { subspace.file_loc_init_value += offset; - lseek (file, -sizeof (subspace), 1); - if (write (file, &subspace, sizeof (subspace)) != sizeof (subspace)) - { perror ("Can't update subspace record"); exit (1); } + check_lseek (file, -subspace_size, 1); + if (write (file, &subspace, subspace_size) != subspace_size) + unexec_error ("Can't update subspace record"); } } @@ -143,9 +160,9 @@ read_header (int file, struct header *hd { /* Read the header in */ - lseek (file, 0, 0); + check_lseek (file, 0, 0); if (read (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) - { perror ("Couldn't read header from a.out file"); exit (1); } + unexec_error ("Couldn't read header from a.out file"); if (hdr->a_magic != EXEC_MAGIC && hdr->a_magic != SHARE_MAGIC && hdr->a_magic != DEMAND_MAGIC) @@ -154,12 +171,9 @@ read_header (int file, struct header *hd exit (1); } - lseek (file, hdr->aux_header_location, 0); + check_lseek (file, hdr->aux_header_location, 0); if (read (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) - { - perror ("Couldn't read auxiliary header from a.out file"); - exit (1); - } + unexec_error ("Couldn't read auxiliary header from a.out file"); } /* Write out the header records into an a.out file. */ @@ -171,12 +185,12 @@ write_header (int file, struct header *h hdr->checksum = calculate_checksum (hdr); /* Write the header back into the a.out file */ - lseek (file, 0, 0); + check_lseek (file, 0, 0); if (write (file, hdr, sizeof (*hdr)) != sizeof (*hdr)) - { perror ("Couldn't write header to a.out file"); exit (1); } - lseek (file, hdr->aux_header_location, 0); + unexec_error ("Couldn't write header to a.out file"); + check_lseek (file, hdr->aux_header_location, 0); if (write (file, auxhdr, sizeof (*auxhdr)) != sizeof (*auxhdr)) - { perror ("Couldn't write auxiliary header to a.out file"); exit (1); } + unexec_error ("Couldn't write auxiliary header to a.out file"); } /* Calculate the checksum of a SOM header record. */ @@ -206,9 +220,9 @@ copy_file (int old, int new, int size) { len = min (size, sizeof (buffer)); if (read (old, buffer, len) != len) - { perror ("Read failure on a.out file"); exit (1); } + unexec_error ("Read failure on a.out file"); if (write (new, buffer, len) != len) - { perror ("Write failure in a.out file"); exit (1); } + unexec_error ("Write failure in a.out file"); } } @@ -225,7 +239,7 @@ copy_rest (int old, int new) if (write (new, buffer, len) != len) break; if (len != 0) - { perror ("Unable to copy the rest of the file"); exit (1); } + unexec_error ("Unable to copy the rest of the file"); } #ifdef DEBUG @@ -270,10 +284,10 @@ unexec (const char *new_name, /* na /* Open the input and output a.out files */ old = open (old_name, O_RDONLY); if (old < 0) - { perror (old_name); exit (1); } + unexec_error (old_name); new = open (new_name, O_CREAT|O_RDWR|O_TRUNC, 0777); if (new < 0) - { perror (new_name); exit (1); } + unexec_error (new_name); /* Read the old headers */ read_header (old, &hdr, &auxhdr); @@ -288,11 +302,11 @@ unexec (const char *new_name, /* na new_size = i - auxhdr.exec_dmem; /* Copy the old file to the new, up to the data space */ - lseek (old, 0, 0); + check_lseek (old, 0, 0); copy_file (old, new, auxhdr.exec_dfile); /* Skip the old data segment and write a new one */ - lseek (old, old_size, 1); + check_lseek (old, old_size, 1); save_data_space (new, &hdr, &auxhdr, new_size); /* Copy the rest of the file */ Only in emacs-24.3-hp/src: unexhp9k800.c~ Only in emacs-24.3-hp/src: unexhp9k800.c.orig Only in emacs-24.3-hp/src: unexhp9k800.c.rej --------------060304030608090303030201--