View Issue Details

This bug affects 1 person(s).
 14
IDProjectCategoryView StatusLast Update
09644Bug reportsSurvey editingpublic2016-01-29 14:52
Reporterriqcles Assigned ToDenisChenu  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version2.05+ 
Fixed in Version2.06+ 
Summary09644: Unable to preview survey when using database sessions - link bug 09592
Description

When using database sessions it is not possible to preview a survey. The welcome page will appear, but when you click next, a session error is displayed:


Error

We are sorry but your session has expired.

Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection.

Log rapport from Firebug :

Previewing a question :
17:45:45.946][trace][system.db.CDbCommand] Executing SQL: DELETE FROM "lime_sessions" WHERE expire<:expire. Bound with :expire=1432143945
17 (ligne 203)

[17:45:45.948][trace][system.db.CDbCommand] Querying SQL: SELECT "data"
FROM "lime_sessions"
WHERE expire>:expire AND id=:id. Bound with :expire=1432143945, :id='lsl08ohp8d1jujag975mkkjij3'

Preview of the survey

[17:39:10.736][trace][system.db.CDbCommand] Executing SQL: DELETE FROM "lime_sessions" WHERE expire<:expire. Bound with :expire=1432143550
index (ligne 75)

[17:39:10.738][trace][system.db.CDbCommand] Querying SQL: SELECT "data"
FROM "lime_sessions"
WHERE expire>:expire AND id=:id. Bound with :expire=1432143550, :id='lsl08ohp8d1jujag975mkkjij3

Steps To Reproduce
1. Enable the following lines in application/config/config.php:

    'session' => array (
        'class' => 'system.web.CDbHttpSession',
        'connectionID' => 'db',
        'sessionTableName' => '{{sessions}}',
    ),
  1. Login to admin interface and select a survey
  2. Click 'execute this survey'
  3. Click 'next' in the survey preview
Additional Information

tested with the latest build: 20150520

OS : CentOS 6.5 / PHP 5.4.33/ 5.3.13
BDD : PostGresql 9.3.4 / 9.3.1 / 8.4.11

TagsNo tags attached.
Attached Files
pgsqllog (54,757 bytes)   
phpinfo_lspg.sondages.pro.html (74,528 bytes)   
session.log (6,237 bytes)   
Bug heat14
Complete LimeSurvey version number (& build)20150520
I will donate to the project if issue is resolvedNo
BrowserFirefox / Internet Explorer
Database type & versionPostGresql 9.3.4
Server OS (if known)CentOS 6.5
Webserver software & version (if known)Apache 2.2
PHP Version PHP 5.4.33

Relationships

related to 09592 closedc_schmitz Unable to preview survey when using database sessions 

Users monitoring this issue

gsmaha, riqcles

Activities

Nickko

Nickko

2015-05-22 10:09

updater   ~32257

I have tested with same build on OVH mutualised hosting Apache / MySQL, I can't reproduce this problem.

Tested with IE and Chrome.

riqcles

riqcles

2015-05-22 17:29

reporter   ~32263

This is normal because the error is encountered only with postgresql

anthony_b

anthony_b

2015-09-09 01:38

reporter   ~33081

I've just tested this (I submitted what appears to be the same issue in 09592), and can confirm the same behaviour on my system. (206+ Build 150831)

I hadn't been able to test the fix released in 2.05+ Build 150520 as we've been in production, but I've just tested locally with that build and the problem is still there as well.

riqcles

riqcles

2015-11-04 11:07

reporter   ~33503

same problem with the latest version : 2.06+ build 151018

riqcles

riqcles

2016-01-06 15:30

reporter   ~34157

same problem with the latest version : 2.06+ build 151205

DenisChenu

DenisChenu

2016-01-17 15:23

developer   ~34284

Last edited: 2016-01-17 15:30

Hi,

Strange I can not reproduce with PostgreSQL 9.1.18 ..... and last GIT version.

http://lspg.sondages.pro/index.php/786677

uNCONNECT : system.db.CDbCommand.query(SELECT "data" FROM "lime_sessions" WHERE expire>:expire AND id=:id. Bound with :expire=1453040785, :id='k049coiqsd9t28jl7o14bp6lf1')

Connect :
system.db.CDbCommand.query(SELECT "data" FROM "lime_sessions" WHERE expire>:expire AND id=:id. Bound with :expire=1453040816, :id='v1v6hit2c3im6bkacq4pjat4r0')
system.db.CDbCommand.execute(DELETE FROM "lime_sessions" WHERE expire<:expire. Bound with :expire=1453040816)

Test activated survey, 1st group (2nd page)
system.db.CDbCommand.query(SELECT "data" FROM "lime_sessions" WHERE expire>:expire AND id=:id. Bound with :expire=1453040887, :id='v1v6hit2c3im6bkacq4pjat4r0')
system.db.CDbCommand.execute(DELETE FROM "lime_sessions" WHERE expire<:expire. Bound with :expire=1453040887)

Preview question : near same

Etc .....

gsmaha

gsmaha

2016-01-19 14:28

reporter   ~34287

The bug arises only if the session contains a class.
On the global administration, there is no bug.
On the administration of survey pages, the bug happens.

  • Explanation :
    PHP uses the character \0 as a mark to serialize class (between class name and class member)
    When PHP opens the session, he reads the data session (from file or DB). If the data can't be parsed, session_destroy() will be called.

In the case of PostgreSQL, the data session is saved in the DB.
So, to protect from SQL injection, LimeSurvey calls the function quoteValue :
-> which calls CDbConnection::quote on Yii
-> which calls PDO::quote
See http://php.net/manual/en/pdo.quote.php

PHP::quote for PostreSQL calls pgsql_handle_quoter()
And in the default case (without the second parameter of PDO::quote), PHP calls the internal function of PostgreSQL : PQescapeStringConn.
See https://github.com/php/php-src/blob/PHP-5.6/ext/pdo_pgsql/pgsql_driver.c#L328 (it's the same with PHP 5.5 and PHP 7)

PQescapeStringConn truncate the string if a char \0 exists before the end.
"If a terminating zero byte is found before length bytes are processed, PQescapeStringConn stops at the zero"
See http://www.postgresql.org/docs/9.1/interactive/libpq-exec.html#LIBPQ-PQESCAPESTRINGCONN

When the session is closed, the data session is saved a last time but the saved session is truncated by PQescapeStringConn.
So, at the next page, PHP try to read the data session but it fails due to the truncate.
See https://github.com/yiisoft/yii/blob/master/framework/web/CHttpSession.php#L89


Here a small example showing the truncate :

<php
$data = "1234\0abcd";

echo "PostgreSQL:\n";
$pdo = new PDO('pgsql:host=localhost;port=5432;user=limes;password=survey;dbname=limesurvey;','limes','survey', array());
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$pdo->exec('SET NAMES '.$pdo->quote('utf8'));

$dataQuoted = $pdo->quote($data);

echo "Quote : ".(($dataQuoted !== false) ? 'OK' : 'FAIL')."\n";
echo $data."\n";
echo $dataQuoted."\n";

echo "len:".strlen($data)."\n";
echo "len:".strlen($dataQuoted)."\n";
?>

The result is :
PostgreSQL:
Quote : OK
1234abcd
'1234'
len:9
len:6

But with MySQL, the result is :
MySQL:
Quote : OK
1234abcd
'1234\0abcd'
len:9
len:12

DenisChenu

DenisChenu

2016-01-21 09:23

developer   ~34305

Last edited: 2016-01-21 09:25

"The bug arises only if the session contains a class.
On the global administration, there is no bug.
On the administration of survey pages, the bug happens."

If i don't make error the "ExpressionManager" is a class, then each time we update a survey and test

  • SUrvey link
  • Question preview link
    We have EM Class.

But i don't find a way to have 2 class in $_SESSION (or

Carsten already set a fix for this :https://github.com/LimeSurvey/LimeSurvey/commit/129a5db2468cc9ef76052d4426941309ae264eaa Disappear ?

Is it here : https://github.com/LimeSurvey/LimeSurvey/commit/6bf9f92302dc199bfe881e3b646a7ae58b125741 ?

gsmaha

gsmaha

2016-01-21 09:36

reporter   ~34308

Yes these links fix the SQL request but the error is due to quoteValue which is called before the SQL request. Even if the SQL seams good, the data is truncated.

DenisChenu

DenisChenu

2016-01-21 09:39

developer   ~34310

Last edited: 2016-01-21 09:39

Do you have a "reproduce" way ? I like to do some test and merge your pull before end of week :)

Ps : if i don't find a way to reproduce, i just merge without testing ;)

gsmaha

gsmaha

2016-01-21 10:06

reporter   ~34312

1) Create a new database and install LimeSurvey

2) In config.php: Uncomment session section

    'session' => array (
        'class' => 'system.web.CDbHttpSession',
        'connectionID' => 'db',
        'sessionTableName' => '{{sessions}}',
    ),

3) Connect to the admin panel
index.php?r=admin

4) Create a survey
index.php?r=admin/survey/sa/newsurvey

5) Valid the form (Title : Test)
index.php?r=admin/survey/sa/view/surveyid/421818

6) Click on Survey Properties -> General settings
Here, you should be disconnected

In postgreSQL log, the SQL query is :

2016-01-21 10:00:21 CET [11366-27] limes@limesurvey LOG: statement: UPDATE "lime_sessions" SET "data"=convert_to('adminlang|s:2:"en";LSWebUser|a:5:{s:11:"returnUrl";s:92:"/tickets/limesurvey/LimeSurvey/index.php?r=admin/survey/sa/editlocalsettings/surveyid/562686";s:4:"id";i:1;s:6:"name";s:5:"admin";s:8:"states";a:0:{}s:6:"plugin";s:6:"Authdb";}loginID|i:1;user|s:5:"admin";full_name|s:13:"Administrator";htmleditormode|s:7:"default";templateeditormode|s:7:"default";questionselectormode|s:7:"default";dateformat|i:1;session_hash|s:64:"ecb7bc0cbffbc5e4b371369089d79104b842f2fd9597364ba47b30d5c576d6be";USER_RIGHT_INITIALSUPERADMIN|i:1;just_logged_in|b:1;loginsummary|s:62:"

<font size="1">Reloading screen. Please wait.</font>";LEMsid|s:6:"562686";FileManagerContext|s:18:"edit:survey:562686";KCFINDER|a:4:{s:5:"types";a:3:{s:5:"files";s:233:"7z aiff asf avi bmp csv doc docx fla flv gif gz gzip ico jpeg jpg mid mov mp3 mp4 mpc mpeg mpg ods odt pdf png ppt pxd qt ram rar rm rmi rmvb rtf sdc sitd swf sxc sxw tar tgz tif tiff txt vsd wav wma wmv xls xlsx xml zip pstpl css js";s:5:"flash";s:233:"7z aiff asf avi bmp csv doc docx fla flv gif gz gzip ico jpeg jpg mid mov mp3 mp4 mpc mpeg mpg ods odt pdf png ppt pxd qt ram rar rm rmi rmvb rtf sdc sitd swf sxc sxw tar tgz tif tiff txt vsd wav wma wmv xls xlsx xml zip pstpl css js";s:6:"images";s:233:"7z aiff asf avi bmp csv doc docx fla flv gif gz gzip ico jpeg jpg mid mov mp3 mp4 mpc mpeg mpg ods odt pdf png ppt pxd qt ram rar rm rmi rmvb rtf sdc sitd swf sxc sxw tar tgz tif tiff txt vsd wav wma wmv xls xlsx xml zip pstpl css js";}s:8:"disabled";b:0;s:9:"uploadURL";s:53:"/tickets/limesurvey/LimeSurvey/upload/surveys/562686/";s:9:"uploadDir";s:61:"/var/www/tickets/limesurvey/LimeSurvey/upload/surveys/562686/";}notificationstate|i:1;next_update_check|O:8:"DateTime":3:{s:4:"date";s:26:"2016-01-22 10:00:21.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:13:"Europe/Berlin";}update_result|b:0;LEMlang|s:2:"en";fieldmap-562686en|a:4:{s:2:"id";a:9:{s:9:"fieldname";s:2:"id";s:3:"sid";s:6:"562686";s:4:"type";s:2:"id";s:3:"gid";s:0:"";s:3:"qid";s:0:"";s:3:"aid";s:0:"";s:5:"title";s:0:"";s:8:"question";s:11:"Response ID";s:10:"group_name";s:0:"";}s:10:"submitdate";a:9:{s:9:"fieldname";s:10:"submitdate";s:4:"type";s:10:"submitdate";s:3:"sid";s:6:"562686";s:3:"gid";s:0:"";s:3:"qid";s:0:"";s:3:"aid";s:0:"";s:5:"title";s:0:"";s:8:"question";s:14:"Date submitted";s:10:"group_name";s:0:"";}s:8:"lastpage";a:9:{s:9:"fieldname";s:8:"lastpage";s:3:"sid";s:6:"562686";s:4:"type";s:8:"lastpage";s:3:"gid";s:0:"";s:3:"qid";s:0:"";s:3:"aid";s:0:"";s:5:"title";s:0:"";s:8:"question";s:9:"Last page";s:10:"group_name";s:0:"";}s:13:"startlanguage";a:9:{s:9:"fieldname";s:13:"startlanguage";s:3:"sid";s:6:"562686";s:4:"type";s:13:"startlanguage";s:3:"gid";s:0:"";s:3:"qid";s:0:"";s:3:"aid";s:0:"";s:5:"title";s:0:"";s:8:"question";s:14:"Start language";s:10:"group_name";s:0:"";}}LEMsingleton|s:22364:"O:21:"LimeExpressionManager":53:{s:25:"', 'UTF8'), "expire"='1453368261' WHERE id='19c5f5ku1hcbb9ia6s91pg2n72'

Just after LimeExpressionManager, there is a \0.
To compare with the correct query, add in framework/web/CDbHttpSession.php in writeSession (line 247) :
file_put_contents('/tmp/ls_write.log', $data."\n---\n");

(Don't use a relative link, because the current path change for register_shutdown_function)

DenisChenu

DenisChenu

2016-01-21 10:16

developer   ~34313

Last edited: 2016-01-21 10:34

Can you sedn me your email at denis<CHEZ>sondages<POINT>pro .

Really can not reproduce .....

I added tracevar(Yii::app()->session); at start of all admin page :)

Uploaded part of pgsql log 'all' : 2 sessions set

gsmaha

gsmaha

2016-01-21 11:02

reporter   ~34315

I forgot to say that this is only for PostgreSQL

DenisChenu

DenisChenu

2016-01-21 11:07

developer   ~34316

I know : and it's PGSQL.log

'connectionString' => 'pgsql:host=localhost;port=5432;user=limesurvey;password=*****;dbname=limesurvey;',

riqcles

riqcles

2016-01-21 14:22

reporter   ~34318

@gsmaha : do you have the same version of postgreSQL like DenisChenu 9.1.18 ?

Mine is 9.4.4

DenisChenu

DenisChenu

2016-01-21 14:44

developer   ~34319

Last edited: 2016-01-21 14:59

@riqcles : it's seems there are a difference betwwen new/old installation.

@@gsmaha : tested with a new clean installation : working

--
-- PostgreSQL database dump

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: lime_sessions; Type: TABLE; Schema: public; Owner: limesurvey; Tablespace:

CREATE TABLE lime_sessions (
id character varying(32) NOT NULL,
expire integer,
data bytea
);

ALTER TABLE public.lime_sessions OWNER TO limesurvey;

--
-- Name: lime_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: limesurvey; Tablespace:

ALTER TABLE ONLY lime_sessions
ADD CONSTRAINT lime_sessions_pkey PRIMARY KEY (id);

--
-- PostgreSQL database dump complete

ANd for the data :
COPY lime_sessions (id, expire, data) FROM stdin;
sqarn4nrilc84gc0s9531umgk0 1453398666 \x61646d696e6c616e677c733a323a22656e223b4c53576562557365727c613a303a7b7d
v9ar4eoictp04vedrt1ppo7lo6 1453391585 \x61646d696e6c...CUT...\45787072657373696f6e4d616e61676572223a35333a7b733a32353a22
.

I create a new instance with a empty DB

gsmaha

gsmaha

2016-01-21 16:10

reporter   ~34320

Last edited: 2016-01-21 16:11

@riqcles No, I have :

  • PostgreSQL 9.4.5
  • PHP 5.6.11-1ubuntu3.1
  • lighttpd/1.4.35

My dump :

-- PostgreSQL database dump

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: lime_sessions; Type: TABLE; Schema: public; Owner: limes; Tablespace:

CREATE TABLE lime_sessions (
id character varying(32) NOT NULL,
expire integer,
data bytea
);

ALTER TABLE lime_sessions OWNER TO limes;

--
-- Data for Name: lime_sessions; Type: TABLE DATA; Schema: public; Owner: limes

COPY lime_sessions (id, expire, data) FROM stdin;
s4a0o5db7h3oaqleltrnkfroj5 1453389673 \x61646d696e6c616e677c733a323a22656e223b4c53576562557365727c613a353a7b733a31313a225f5f72657475726e55726c223b733a39323a222f7469636b6574732f6c696d657
375727665792f4c696d655375727665792f696e6465782e7068703f723d61646d696e2f7375727665792f73612f656469746c6f63616c73657474696e67732f73757276657969642f393
736353531223b733a343a225f5f6964223b693a313b733a363a225f5f6e616d65223b733a353a2261646d696e223b733a383a225f5f737461746573223b613a303a7b7d733a363a22706
c7567696e223b733a363a22417574686462223b7d6c6f67696e49447c693a313b757365727c733a353a2261646d696e223b66756c6c5f6e616d657c733a31333a2241646d696e6973747
261746f72223b68746d6c656469746f726d6f64657c733a373a2264656661756c74223b74656d706c617465656469746f726d6f64657c733a373a2264656661756c74223b71756573746
96f6e73656c6563746f726d6f64657c733a373a2264656661756c74223b64617465666f726d61747c693a313b73657373696f6e5f686173687c733a36343a22656362376263306362666
66263356534623337313336393038396437393130346238343266326664393539373336346261343762333064356335373664366265223b555345525f52494748545f494e495449414c5
35550455241444d494e7c693a313b6a7573745f6c6f676765645f696e7c623a313b6c6f67696e73756d6d6172797c733a36323a223c703e3c666f6e742073697a653d2231223e3c693e5
2656c6f6164696e672073637265656e2e20506c6561736520776169742e3c2f693e3c2f666f6e743e223b4c454d7369647c733a363a22393736353531223b46696c654d616e616765724
36f6e746578747c733a31383a22656469743a7375727665793a393736353531223b4b4346494e4445527c613a343a7b733a353a227479706573223b613a333a7b733a353a2266696c657
3223b733a3233333a22377a2061696666206173662061766920626d702063737620646f6320646f637820666c6120666c762067696620677a20677a69702069636f206a706567206a706
7206d6964206d6f76206d7033206d7034206d7063206d706567206d7067206f6473206f64742070646620706e6720707074207078642071742072616d2072617220726d20726d6920726
d766220727466207364632073697464207377662073786320737877207461722074677a20746966207469666620747874207673642077617620776d6120776d7620786c7320786c73782
0786d6c207a697020707374706c20637373206a73223b733a353a22666c617368223b733a3233333a22377a2061696666206173662061766920626d702063737620646f6320646f63782
0666c6120666c762067696620677a20677a69702069636f206a706567206a7067206d6964206d6f76206d7033206d7034206d7063206d706567206d7067206f6473206f6474207064662
0706e6720707074207078642071742072616d2072617220726d20726d6920726d766220727466207364632073697464207377662073786320737877207461722074677a2074696620746
9666620747874207673642077617620776d6120776d7620786c7320786c737820786d6c207a697020707374706c20637373206a73223b733a363a22696d61676573223b733a3233333a2
2377a2061696666206173662061766920626d702063737620646f6320646f637820666c6120666c762067696620677a20677a69702069636f206a706567206a7067206d6964206d6f762
06d7033206d7034206d7063206d706567206d7067206f6473206f64742070646620706e6720707074207078642071742072616d2072617220726d20726d6920726d76622072746620736
4632073697464207377662073786320737877207461722074677a20746966207469666620747874207673642077617620776d6120776d7620786c7320786c737820786d6c207a6970207
07374706c20637373206a73223b7d733a383a2264697361626c6564223b623a303b733a393a2275706c6f616455524c223b733a35333a222f7469636b6574732f6c696d6573757276657
92f4c696d655375727665792f75706c6f61642f737572766579732f3937363535312f223b733a393a2275706c6f6164446972223b733a36313a222f7661722f7777772f7469636b65747
32f6c696d657375727665792f4c696d655375727665792f75706c6f61642f737572766579732f3937363535312f223b7d6e6f74696669636174696f6e73746174657c693a313b6e65787
45f7570646174655f636865636b7c4f3a383a224461746554696d65223a333a7b733a343a2264617465223b733a32363a22323031362d30312d32322031353a35373a31332e303030303
030223b733a31333a2274696d657a6f6e655f74797065223b693a333b733a383a2274696d657a6f6e65223b733a31333a224575726f70652f4265726c696e223b7d7570646174655f726
573756c747c623a303b4c454d6c616e677c733a323a22656e223b6669656c646d61702d393736353531656e7c613a343a7b733a323a226964223b613a393a7b733a393a226669656c646
e616d65223b733a323a226964223b733a333a22736964223b733a363a22393736353531223b733a343a2274797065223b733a323a226964223b733a333a22676964223b733a303a22223
b733a333a22716964223b733a303a22223b733a333a22616964223b733a303a22223b733a353a227469746c65223b733a303a22223b733a383a227175657374696f6e223b733a31313a2
2526573706f6e7365204944223b733a31303a2267726f75705f6e616d65223b733a303a22223b7d733a31303a227375626d697464617465223b613a393a7b733a393a226669656c646e6
16d65223b733a31303a227375626d697464617465223b733a343a2274797065223b733a31303a227375626d697464617465223b733a333a22736964223b733a363a22393736353531223
b733a333a22676964223b733a303a22223b733a333a22716964223b733a303a22223b733a333a22616964223b733a303a22223b733a353a227469746c65223b733a303a22223b733a383
a227175657374696f6e223b733a31343a2244617465207375626d6974746564223b733a31303a2267726f75705f6e616d65223b733a303a22223b7d733a383a226c61737470616765223
b613a393a7b733a393a226669656c646e616d65223b733a383a226c61737470616765223b733a333a22736964223b733a363a22393736353531223b733a343a2274797065223b733a383
a226c61737470616765223b733a333a22676964223b733a303a22223b733a333a22716964223b733a303a22223b733a333a22616964223b733a303a22223b733a353a227469746c65223
b733a303a22223b733a383a227175657374696f6e223b733a393a224c6173742070616765223b733a31303a2267726f75705f6e616d65223b733a303a22223b7d733a31333a227374617
2746c616e6775616765223b613a393a7b733a393a226669656c646e616d65223b733a31333a2273746172746c616e6775616765223b733a333a22736964223b733a363a2239373635353
1223b733a343a2274797065223b733a31333a2273746172746c616e6775616765223b733a333a22676964223b733a303a22223b733a333a22716964223b733a303a22223b733a333a226
16964223b733a303a22223b733a353a227469746c65223b733a303a22223b733a383a227175657374696f6e223b733a31343a225374617274206c616e6775616765223b733a31303a226
7726f75705f6e616d65223b733a303a22223b7d7d4c454d73696e676c65746f6e7c733a32323336343a224f3a32313a224c696d6545787072657373696f6e4d616e61676572223a35333
a7b733a32353a22
.

--
-- Name: lime_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: limes; Tablespace:

ALTER TABLE ONLY lime_sessions
ADD CONSTRAINT lime_sessions_pkey PRIMARY KEY (id);

--
-- PostgreSQL database dump complete

gsmaha

gsmaha

2016-01-21 16:14

reporter   ~34321

Last edited: 2016-01-21 16:16

Note : PHP version is important because this is PHP which calls PQescapeStringConn. May be in your version, PHP doesn't call PQescapeStringConn.

DenisChenu

DenisChenu

2016-01-21 16:51

developer   ~34322

Last edited: 2016-01-21 16:52

Can test with 5.6 but actually : PHP Version 5.4.45-1~dotdeb+7.1

5.4 for ricles and me

gsmaha

gsmaha

2016-01-21 17:27

reporter   ~34323

I checked PHP, PQescapeStringConn is always called...

See https://github.com/php/php-src/blob/PHP-5.4/ext/pdo_pgsql/pgsql_driver.c#L330

This is may be the serialization method used by PHP.
I will check the release note.

gsmaha

gsmaha

2016-01-21 18:08

reporter   ~34324

Last edited: 2016-01-21 18:09

What is your configuration of php.ini, in particular session.serialize_handler ?

See http://php.net/manual/fr/session.configuration.php#ini.session.serialize-handler

On my php.ini, this :
session.serialize_handler = php

DenisChenu

DenisChenu

2016-01-21 18:25

developer   ~34326

Last edited: 2016-01-21 18:25

php too.

For the mail (pgsql log)

I look at you log you have:

2016-01-21 17:00:34 CET [20693-9] limes@limesurvey LOG: statement: UPDATE "lime_sessions" SET "data"=convert_to('DATA in onle line with " but no simple quote', 'UTF8'), "expire"='1453393474' WHERE id='b9i72nbelqnn3os3tsp9kjjje5'

and after
2016-01-21 17:00:43 CET [20694-2] limes@limesurvey LOG: statement: DELETE FROM "lime_sessions" WHERE expire<'1453392043'

gsmaha

gsmaha

2016-01-21 18:35

reporter   ~34328

Last edited: 2016-01-21 18:38

Yes, I have investisgate and all these requests are called by session_start() beacause

session_start calls :
1) session_open : CDbHttpSession::openSession
DELETE FROM "lime_sessions" WHERE expire<'1453392034'

2) session_read : CDbHttpSession::readSession
SELECT "data"
FROM "lime_sessions"
WHERE expire>'1453392071' AND id='b9i72nbelqnn3os3tsp9kjjje5'

3) session_destroy : CDbHttpSession::destroySession
DELETE FROM "lime_sessions" WHERE id='b9i72nbelqnn3os3tsp9kjjje5'

See files :
framework/web/CHttpSession.php
framework/web/CDbHttpSession.php

I think session_destroy is called due to a bad reading on the step session_read (PHP can't parse data session)
See the session handler session_set_save_handler : http://php.net/manual/en/function.session-set-save-handler.php
"The value this callback returns must be in exactly the same serialized format that was originally passed for storage to the write callback."

And I think the bad reading is due to the previous UPDATE.
As you can see, the data session in the file is different with the data session in the SQL query from Postgresql log.

gsmaha

gsmaha

2016-01-22 09:44

reporter   ~34341

Last edited: 2016-01-22 09:49

Ok, after seeing your log. We are agree that even if the bug doesn't happen, your saved session is truncated.
I don't understand why PHP in session_start doesn't call session_destroy after session_read whereas it should do it.

DenisChenu

DenisChenu

2016-01-22 10:16

developer   ~34344

Yes, and actually don't see the bug, but there are surely bug in Surtvey with some Expression inside ....

gsmaha

gsmaha

2016-01-22 11:00

reporter   ~34346

I found this bug which is not fixed on 5.4.45
https://bugs.php.net/bug.php?id=71038

gsmaha

gsmaha

2016-01-22 11:02

reporter   ~34347

Last edited: 2016-01-22 11:03

Can you log session_status() in framework/web/CHttpSession.php after session_start() line 114, remove @ on session_start and log boolean returns by session_start ?

gsmaha

gsmaha

2016-01-22 11:09

reporter   ~34348

PHP code :

$ses = session_start();
$sta = session_status();
file_put_contents("/tmp/session.log", "-----\nURL : ".$_SERVER['REQUEST_URI']."\nSESSION BOOL : ".($ses ? 'TRUE' : 'FALSE')."\nSESSION STATUS : ".($sta == PHP_SESSION_DISABLED ? 'PHP_SESSION_DISABLED' : ($sta == PHP_SESSION_NONE ? 'PHP_SESSION_NONE' : 'PHP_SESSION_ACTIVE'))."\n", FILE_APPEND );

My result :


URL : /LimeSurvey/index.php?r=admin/authentication/sa/login
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/authentication/sa/login
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/authentication/sa/login
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/survey/sa/view/surveyid/549852
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/survey/sa/view/surveyid/549852
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/survey/sa/view/surveyid/549852
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/survey/sa/editsurveysettings/surveyid/549852
SESSION BOOL : FALSE
SESSION STATUS : PHP_SESSION_NONE

URL : /LimeSurvey/index.php?r=admin/survey/sa/editsurveysettings/surveyid/549852
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/survey/sa/editsurveysettings/surveyid/549852
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/authentication/sa/login
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/authentication/sa/login
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

URL : /LimeSurvey/index.php?r=admin/authentication/sa/login
SESSION BOOL : TRUE
SESSION STATUS : PHP_SESSION_ACTIVE

gsmaha

gsmaha

2016-01-22 11:16

reporter   ~34349

Crazy, there is the same code between PHP 5.4.45 et PHP 5.6 ...
https://github.com/php/php-src/blob/PHP-5.4.45/ext/session/session.c#L220
https://github.com/php/php-src/blob/PHP-5.6/ext/session/session.c#L233

gsmaha

gsmaha

2016-01-22 11:56

reporter   ~34350

Last edited: 2016-01-22 12:06

Ok your session.log is always valid ...

But in any case, my fix permits to have a complete saved session.
This bug between our different version of PHP is another matter.
What do you think about to validate it ?

DenisChenu

DenisChenu

2016-01-22 12:09

developer   ~34351

debug @ 2 :
PHP warning
session_start(): Trying to destroy uninitialized session

Uploaded the session.log and the $_SESSION for group preview.

I think i have something, excepot why you have $_session issue and not me.

LimeExpressionManager::singleton() can be taken from $_SESSION : https://github.com/LimeSurvey/LimeSurvey/blob/master/application/helpers/expressions/em_manager_helper.php#L679

With pgsql/db session : $_SESSION['LEMsingleton'] is never set
with mysql/file session on same server : $_SESSION['LEMsingleton'] is set after

Then : the server redo completely the LEM for each page

DenisChenu

DenisChenu

2016-01-22 12:10

developer   ~34352

PS: yes : and i have a way to better understand why i need the fix too.

Let me just merging tempporary in my system :)

DenisChenu

DenisChenu

2016-01-22 12:24

developer   ~34353

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=16892

DenisChenu

DenisChenu

2016-01-22 12:25

developer   ~34354

OK : now all is clean : $_SESSION['LEMsingleton'] is set for the second page

Great thanks :)

gsmaha

gsmaha

2016-01-22 12:28

reporter   ~34355

debug @ 2 :
PHP warning
session_start(): Trying to destroy uninitialized session

Nice ! I doesn't have warning on session_start ! This is our difference !!!

Ahah ! I found it :D

php_session_initialize calls session_read which calls session_decode which calls destroy.
But in your case, the session is not yet active.

In PHP 5.4.45 :
PS(session_status) = php_session_active; is call AFTER php_session_initialize(TSRMLS_C);
See https://github.com/php/php-src/blob/PHP-5.4.45/ext/session/session.c#L1510

In PHP 5.6 :
This is inverted :
See https://github.com/php/php-src/blob/PHP-5.6/ext/session/session.c#L505

DenisChenu

DenisChenu

2016-01-22 15:02

developer   ~34359

rcqles say PHP version PHP 5.4.33

gsmaha

gsmaha

2016-01-22 18:33

reporter   ~34363

@DenisChenu Yes, ... I don't know why but it is fixed now :)

Related Changesets

LimeSurvey: master 3d053806

2016-01-15 13:54

gsmaha


Details Diff
Fixed issue 09644: Unable to preview survey when using database sessions - link bug 09592
Dev: Overwrite quoteValue in DbConnection
Dev: Implement DbHttpSession class: Call toQuoteValue with PDO::PARAM_LOB to get directly a bytea value
Dev: Edit config sample and installer
Dev: Edit kcfinder to check for application.core.web.DbHttpSession
Affected Issues
09644
mod - application/config/config-sample-dblib.php Diff File
mod - application/config/config-sample-mysql.php Diff File
mod - application/config/config-sample-pgsql.php Diff File
mod - application/config/config-sample-sqlsrv.php Diff File
mod - application/controllers/InstallerController.php Diff File
mod - application/core/db/DbConnection.php Diff File
add - application/core/web/DbHttpSession.php Diff File
mod - application/helpers/remotecontrol/remotecontrol_handle.php Diff File
mod - third_party/kcfinder/core/bootstrap.php Diff File

LimeSurvey: master a0cf88da

2016-01-22 12:24

DenisChenu


Details Diff
Merge pull request #416 from GuillaumeSmaha/fix_session_expire_postgresql

Fixed issue 09644: Unable to preview survey when using database sessions - link bug 09592
Affected Issues
09644
mod - application/config/config-sample-dblib.php Diff File
mod - application/config/config-sample-mysql.php Diff File
mod - application/config/config-sample-pgsql.php Diff File
mod - application/config/config-sample-sqlsrv.php Diff File
mod - application/controllers/InstallerController.php Diff File
mod - application/core/db/DbConnection.php Diff File
add - application/core/web/DbHttpSession.php Diff File
mod - application/helpers/remotecontrol/remotecontrol_handle.php Diff File
mod - third_party/kcfinder/core/bootstrap.php Diff File

Issue History

Date Modified Username Field Change
2015-05-21 16:30 riqcles New Issue
2015-05-22 10:09 Nickko Note Added: 32257
2015-05-22 17:29 riqcles Note Added: 32263
2015-09-07 11:13 riqcles Issue Monitored: riqcles
2015-09-08 16:50 c_schmitz Relationship added related to 09592
2015-09-09 01:38 anthony_b Note Added: 33081
2015-11-04 11:07 riqcles Note Added: 33503
2016-01-06 15:30 riqcles Note Added: 34157
2016-01-17 15:23 DenisChenu Note Added: 34284
2016-01-17 15:25 DenisChenu Note Edited: 34284
2016-01-17 15:25 DenisChenu Note Edited: 34284
2016-01-17 15:28 DenisChenu Note Edited: 34284
2016-01-17 15:30 DenisChenu Note Edited: 34284
2016-01-19 14:28 gsmaha Note Added: 34287
2016-01-21 09:23 DenisChenu Note Added: 34305
2016-01-21 09:25 DenisChenu Note Edited: 34305
2016-01-21 09:36 gsmaha Note Added: 34308
2016-01-21 09:39 DenisChenu Note Added: 34310
2016-01-21 09:39 DenisChenu Note Edited: 34310
2016-01-21 10:06 gsmaha Note Added: 34312
2016-01-21 10:16 DenisChenu Note Added: 34313
2016-01-21 10:32 DenisChenu Note Edited: 34313
2016-01-21 10:34 DenisChenu Note Edited: 34313
2016-01-21 10:35 DenisChenu File Added: pgsqllog
2016-01-21 11:02 gsmaha Note Added: 34315
2016-01-21 11:07 DenisChenu Note Added: 34316
2016-01-21 14:22 riqcles Note Added: 34318
2016-01-21 14:44 DenisChenu Note Added: 34319
2016-01-21 14:56 DenisChenu Note Edited: 34319
2016-01-21 14:59 DenisChenu Note Edited: 34319
2016-01-21 16:10 gsmaha Note Added: 34320
2016-01-21 16:11 gsmaha Note Edited: 34320
2016-01-21 16:14 gsmaha Note Added: 34321
2016-01-21 16:16 gsmaha Note Edited: 34321
2016-01-21 16:51 DenisChenu Note Added: 34322
2016-01-21 16:52 DenisChenu Note Edited: 34322
2016-01-21 17:27 gsmaha Note Added: 34323
2016-01-21 18:08 gsmaha Note Added: 34324
2016-01-21 18:09 gsmaha Note Edited: 34324
2016-01-21 18:25 DenisChenu Note Added: 34326
2016-01-21 18:25 DenisChenu Note Edited: 34326
2016-01-21 18:27 DenisChenu File Added: phpinfo_lspg.sondages.pro.html
2016-01-21 18:35 gsmaha Note Added: 34328
2016-01-21 18:36 gsmaha Note Edited: 34328
2016-01-21 18:38 gsmaha Note Edited: 34328
2016-01-22 08:32 DenisChenu Assigned To => DenisChenu
2016-01-22 08:32 DenisChenu Status new => assigned
2016-01-22 09:44 gsmaha Note Added: 34341
2016-01-22 09:49 gsmaha Note Edited: 34341
2016-01-22 10:16 DenisChenu Note Added: 34344
2016-01-22 11:00 gsmaha Note Added: 34346
2016-01-22 11:02 gsmaha Note Added: 34347
2016-01-22 11:03 gsmaha Note Edited: 34347
2016-01-22 11:03 gsmaha Note Edited: 34347
2016-01-22 11:09 gsmaha Note Added: 34348
2016-01-22 11:16 gsmaha Note Added: 34349
2016-01-22 11:47 DenisChenu File Added: session.log
2016-01-22 11:56 gsmaha Note Added: 34350
2016-01-22 11:58 gsmaha Issue Monitored: gsmaha
2016-01-22 12:06 gsmaha Note Edited: 34350
2016-01-22 12:09 DenisChenu Note Added: 34351
2016-01-22 12:10 DenisChenu Note Added: 34352
2016-01-22 12:24 gsmaha Changeset attached => LimeSurvey master 3d053806
2016-01-22 12:24 DenisChenu Changeset attached => LimeSurvey master a0cf88da
2016-01-22 12:24 DenisChenu Note Added: 34353
2016-01-22 12:24 DenisChenu Resolution open => fixed
2016-01-22 12:25 DenisChenu Note Added: 34354
2016-01-22 12:25 DenisChenu Status assigned => resolved
2016-01-22 12:25 DenisChenu Fixed in Version => 2.06+
2016-01-22 12:28 gsmaha Note Added: 34355
2016-01-22 15:02 DenisChenu Note Added: 34359
2016-01-22 18:33 gsmaha Note Added: 34363
2016-01-29 14:52 c_schmitz Status resolved => closed
2019-11-01 17:25 c_schmitz Category Survey design => Survey editing