php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31247 Incorrect C code in unpack.c causes misbehavior and warnings
Submitted: 2004-12-22 15:52 UTC Modified: 2004-12-23 11:49 UTC
From: sefer at hotmail dot com Assigned:
Status: Not a bug Package: Compile Warning
PHP Version: 4.3.10 OS: Linux redhat 9
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sefer at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-12-22 15:52 UTC] sefer at hotmail dot com
Description:
------------
In the recent PHP release 4.3.10 there had been added a bug to the unpack (PHP_FUNCTION(unpack)) function in unpack.c

The code that manifests the problem is this:
$h = unpack('H*hex', $data);

The result would be:
Warning: unpack(): Type H: outside of string in /my_file.php on line 20

The reason is a change in the function which using the current compiler (Red Hat Linux 3.2.3-42) generates incorrect behavior when "break" is placed within a curly braces block (within a "switch" statement) which causes break to leave the current scope but then continue falling down through the "switch" elements.

For example this code:
  case 'C': {
      int issigned = (type == 'c') ? (input[inputpos] & 0x80) : 0;
      long v = php_unpack(&input[inputpos], 1, issigned, byte_map);
      add_assoc_long(return_value, n, v);
      break;
  }
  case 's':

The correct setup needs to move the "break" outside the {...} scope, which would then fix the problem.
This behavior is apparent in several places throughout that function and needs to be corrected in all of them.

Thanks,
    Sefer.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-22 16:17 UTC] iliaa@php.net
Please fix your compiler, the position of the break statment should not matter.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 17:01:32 2024 UTC