php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6559 yp_first() and yp_next() results handled wrong in ext/yp/yp.c
Submitted: 2000-09-05 14:31 UTC Modified: 2007-04-04 19:05 UTC
From: gert at gerts dot net Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.0.2 OS: Solaris 8 (x86)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gert at gerts dot net
New email:
PHP Version: OS:

 

 [2000-09-05 14:31 UTC] gert at gerts dot net
The key/value pairs that libnsl's yp_first/yp_next return contain
a trailing NEWLINE as per NIS specs. These NEWLINEs are
not chopped off before returning the key/value pair to the users's PHP
code. Hence you end up with newlines in PHP hashes.

Below is the context diff for the fix.

regards,
Gert

*** yp.c.orig   Mon Jun  5 21:47:45 2000
--- yp.c        Tue Sep  5 19:37:54 2000
***************
*** 151,156 ****
--- 151,158 ----
                RETURN_FALSE;
        }
        array_init(return_value);
+       outkey[outkeylen] = 0;
+       outval[outvallen] = 0;
        add_assoc_string(return_value,"key",outkey,1);
        add_assoc_string(return_value,"value",outval,1);
  }
***************
*** 175,180 ****
--- 177,184 ----
                RETURN_FALSE;
        }
  
+       outkey[outkeylen] = 0;
+       outval[outvallen] = 0;
        array_init(return_value);
        add_assoc_string(return_value,outkey,outval,1);
  }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-18 17:05 UTC] ohrn@php.net
This depends on the data you put in the map in the first place. Properly created maps do not include linebreaks.

It's not up to PHP to second guess the administrator of the YP domain. :)
 [2001-03-22 09:57 UTC] gert at gerts dot net
Reaction to [2001-03-18 17:05:11] ohrn@php.net's comment:

You're wrong in saying that having a newline at the end
of a key/value pair is dependent on the data you put
in the map. Sure, if you put newlines in the map
you'll bound to get them out; BUT there's allways
an extra newline added.

From the SunOS 7 and 8 manuals (ypclnt(3N)):

[..]
For  each  outkey  and  outval, two extra bytes of
memory are allocated at the end  that  contain  NEWLINE
and null, respectively, but these two bytes are not
reflected in outkeylen or outvallen .
[..]

Meaning for keys x and value y, you'll get:

outkeylen = 1; outvallen = 1;
outkey[] = { 0x78, 0x0a, 0x00 };
outval[] = { 0x79, 0x0a, 0x00 };

Which requires chopping off the newline in case you
must use the key and value as a C string. The latter
is precisely what php needs/does, the former was
missing from the glue code.

Proof me wrong ;-). I've observed the original code
fail...

Regards
Gert

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 19:01:30 2024 UTC