com php-src: fix implicit st_rdev element handling when negative value was passed: ext/standard/file.c ext/standard/filestat.c
| From: | Anatol Belski | Date: | Fri, 29 Aug 2014 11:30:53 +0000 |
| Subject: | com php-src: fix implicit st_rdev element handling when negative value was passed: ext/standard/file.c ext/standard/filestat.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81296@lists.php.net to get a copy of this message | ||
Commit: 13ccda724988d30d0522207344c0e4f9b0cdc2b4
Author: Anatol Belski <ab@php.net> Fri, 29 Aug 2014 13:30:53 +0200
Parents: 451856420c42d4fc2f2ab579135c23eb78ae7378
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=13ccda724988d30d0522207344c0e4f9b0cdc2b4
Log:
fix implicit st_rdev element handling when negative value was passed
Changed paths:
M ext/standard/file.c
M ext/standard/filestat.c
Diff:
diff --git a/ext/standard/file.c b/ext/standard/file.c
index d9fa64e..21f9a75 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -1577,7 +1577,19 @@ PHP_NAMED_FUNCTION(php_if_fstat)
ZVAL_LONG(&stat_uid, stat_ssb.sb.st_uid);
ZVAL_LONG(&stat_gid, stat_ssb.sb.st_gid);
#ifdef HAVE_ST_RDEV
+# ifdef PHP_WIN32
+ /* It is unsigned, so if a negative came from userspace, it'll
+ convert to UINT_MAX, but we wan't to keep the userspace value.
+ Almost the same as in php_fstat. This is ugly, but otherwise
+ we would have to maintain a fully compatible struct stat. */
+ if ((int)stat_ssb.sb.st_rdev < 0) {
+ ZVAL_LONG(&stat_rdev, (int)stat_ssb.sb.st_rdev);
+ } else {
+ ZVAL_LONG(&stat_rdev, stat_ssb.sb.st_rdev);
+ }
+# else
ZVAL_LONG(&stat_rdev, stat_ssb.sb.st_rdev);
+# endif
#else
ZVAL_LONG(&stat_rdev, -1);
#endif
diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c
index 216e5b2..992f99d 100644
--- a/ext/standard/filestat.c
+++ b/ext/standard/filestat.c
@@ -1019,7 +1019,18 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int
typ
ZVAL_LONG(&stat_uid, stat_sb->st_uid);
ZVAL_LONG(&stat_gid, stat_sb->st_gid);
#ifdef HAVE_ST_RDEV
+# ifdef PHP_WIN32
+ /* It is unsigned, so if a negative came from userspace, it'll
+ convert to UINT_MAX, but we wan't to keep the userspace value.
+ Almost the same as in php_if_fstat. */
+ if ((int)stat_sb->st_rdev < 0) {
+ ZVAL_LONG(&stat_rdev, (int)stat_sb->st_rdev);
+ } else {
ZVAL_LONG(&stat_rdev, stat_sb->st_rdev);
+ }
+# else
+ ZVAL_LONG(&stat_rdev, stat_sb->st_rdev);
+# endif
#else
ZVAL_LONG(&stat_rdev, -1);
#endif