I am working on Cake PHP Ftramework. My task is to verify if a transaction is genuine. I am trying the following with transaction ID (recieved when payment success).
try {
$stripe = new \Stripe\StripeClient(STRIPE_SECRET_KEY);
$stripe->transfers->retrieve('pi_xxxxxxxxxxxxxxxxxxxxxx', []);
echo "<pre>"; print_r( $stripe ); die;
} catch(\Stripe\Error\Card $e) {
echo "<pre>in catch<br>"; print_r($e->getMessage());
die;
}
And here is what i am gettng in error logs.
Error: [Stripe\Exception\InvalidRequestException] No such transfer: 'pi_xxxxxxxxxxxxxxxxxxxxxxxxxxxx' (E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php:38)
#0 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Exception\InvalidRequestException.php(35): Stripe\Exception\ApiErrorException::factory('No such transfe...', 404, '{\n "error": {\n...', Array, Object(Stripe\Util\CaseInsensitiveArray), 'resource_missin...')
#1 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(189): Stripe\Exception\InvalidRequestException::factory('No such transfe...', 404, '{\n "error": {\n...', Array, Object(Stripe\Util\CaseInsensitiveArray), 'resource_missin...', 'transfer')
#2 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(151): Stripe\ApiRequestor::_specificAPIError('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array, Array)
#3 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(478): Stripe\ApiRequestor->handleErrorResponse('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array)
#4 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\ApiRequestor.php(120): Stripe\ApiRequestor->_interpretResponse('{\n "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray))
#5 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\BaseStripeClient.php(134): Stripe\ApiRequestor->request('get', '/v1/transfers/p...', Array, Array)
#6 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Service\AbstractService.php(59): Stripe\BaseStripeClient->request('get', '/v1/transfers/p...', Array, Object(Stripe\Util\RequestOptions))
#7 E:\Wamp64\www\TrainerSlate\vendor\stripe\stripe-php\lib\Service\TransferService.php(115): Stripe\Service\AbstractService->request('get', '/v1/transfers/p...', Array, NULL)
#8 E:\Wamp64\www\TrainerSlate\src\Controller\ApisController.php(4516): Stripe\Service\TransferService->retrieve('pi_1ILNxXKDtVMA...', Array)
#9 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Controller\Controller.php(609): App\Controller\ApisController->verifyTransaction()
#10 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\ActionDispatcher.php(120): Cake\Controller\Controller->invokeAction()
#11 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\ActionDispatcher.php(94): Cake\Http\ActionDispatcher->_invoke(Object(App\Controller\ApisController))
#12 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\BaseApplication.php(234): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#13 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#14 E:\Wamp64\www\TrainerSlate\vendor\admad\cakephp-social-auth\src\Middleware\SocialAuthMiddleware.php(161): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#15 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): ADmad\SocialAuth\Middleware\SocialAuthMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#16 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Routing\Middleware\RoutingMiddleware.php(162): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#17 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#18 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Routing\Middleware\AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#19 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#20 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Error\Middleware\ErrorHandlerMiddleware.php(96): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#21 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#22 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#23 E:\Wamp64\www\TrainerSlate\vendor\cakephp\cakephp\src\Http\Server.php(97): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#24 E:\Wamp64\www\TrainerSlate\webroot\index.php(40): Cake\Http\Server->run()
#25 {main}
Request URL: /Apis/verifyTransaction/
In this case to retrieve the PaymentIntent from the API using a pi_xxx PaymentIntent ID, then the PHP code to do this is [1]:
$pi = $stripe->paymentIntents->retrieve(
'pi_xxx',
[]
);
[1] https://stripe.com/docs/api/payment_intents/retrieve?lang=php
I am developing an app in Flutter and dart , using SQFLite database and Firestore , I want when the user click on logout button , app deletes the sqflite database and return the user to Log In Screen and when Log In fetch the data user info log in from Firestore ,and it deletes the DB , but the problem is when I want to log in again to app , it shows me this error ..
Please need help
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: DatabaseException(database_closed 1)
#0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:12:7)
E/flutter (28706): <asynchronous suspension>
E/flutter (28706): #1 SqfliteDatabaseFactoryImpl.wrapDatabaseException
(package:sqflite/src/factory_impl.dart:25:7)
E/flutter (28706): #2 SqfliteDatabaseMixin.safeInvokeMethod
(package:sqflite/src/database_mixin.dart:188:15)
E/flutter (28706): #3 SqfliteDatabaseMixin.txnRawInsert.<anonymous closure>
(package:sqflite/src/database_mixin.dart:363:14)
E/flutter (28706): #4 SqfliteDatabaseMixin.txnSynchronized.<anonymous closure>
(package:sqflite/src/database_mixin.dart:307:22)
E/flutter (28706): #5 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:32:26)
E/flutter (28706): #6 SqfliteDatabaseMixin.txnSynchronized
(package:sqflite/src/database_mixin.dart:303:43)
E/flutter (28706): #7 SqfliteDatabaseMixin.txnWriteSynchronized
(package:sqflite/src/database_mixin.dart:325:7)
E/flutter (28706): #8 SqfliteDatabaseMixin.txnRawInsert
(package:sqflite/src/database_mixin.dart:362:12)
E/flutter (28706): #9 SqfliteDatabaseExecutorMixin.rawInsert
(package:sqflite/src/database_mixin.dart:49:15)
E/flutter (28706): #10 SqfliteDatabaseExecutorMixin.insert
(package:sqflite/src/database_mixin.dart:59:12)
E/flutter (28706): #11 SQFliteDBHelper.SAVE_USER
(package:health_calorie_db/settings_in_app/sqflite_db_helper.dart:86:20)
E/flutter (28706): <asynchronous suspension>
E/flutter (28706): #12 userServices.saveToSQFLiteDB
(package:health_calorie_db/dbServicesManager/userServices.dart:72:13)
E/flutter (28706): #13 userServices.logInCheck
(package:health_calorie_db/dbServicesManager/userServices.dart:99:10)
E/flutter (28706): <asynchronous suspension>
E/flutter (28706): #14 loginState.checkValidationForms
(package:health_calorie_db/ui_classes/log_in_up_pages/log_in_page.dart:25:22)
E/flutter (28706): #15 loginState.build.<anonymous closure>.<anonymous closure>
(package:health_calorie_db/ui_classes/log_in_up_pages/log_in_page.dart:112:60)
E/flutter (28706): #16 _createButton.build.<anonymous closure>
(package:health_calorie_db/ui_classes/log_in_up_pages/log_in_page.dart:165:9)
E/flutter (28706): #17 _InkResponseState._handleTap
(package:flutter/src/material/ink_well.dart:706:14)
E/flutter (28706): #18 _InkResponseState.build.<anonymous closure>
(package:flutter/src/material/ink_well.dart:789:36)
E/flutter (28706): #19 GestureRecognizer.invokeCallback
(package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (28706): #20 TapGestureRecognizer.handleTapUp
(package:flutter/src/gestures/tap.dart:486:11)
E/flutter (28706): #21 BaseTapGestureRecognizer._checkUp
(package:flutter/src/gestures/tap.dart:264:5)
E/flutter (28706): #22 BaseTapGestureRecognizer.acceptGesture
(package:flutter/src/gestures/tap.dart:236:7)
E/flutter (28706): #23 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (28706): #24 GestureBinding.handleEvent
(package:flutter/src/gestures/binding.dart:222:20)
E/flutter (28706): #25 GestureBinding.dispatchEvent
(package:flutter/src/gestures/binding.dart:198:22)
E/flutter (28706): #26 GestureBinding._handlePointerEvent
(package:flutter/src/gestures/binding.dart:156:7)
E/flutter (28706): #27 GestureBinding._flushPointerEventQueue
(package:flutter/src/gestures/binding.dart:102:7)
E/flutter (28706): #28 GestureBinding._handlePointerDataPacket
(package:flutter/src/gestures/binding.dart:86:7)
E/flutter (28706): #29 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter (28706): #30 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (28706): #31 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter (28706): #32 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter (28706): #33 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
and here is the Code
FlatButton(
child: Text('Yes'),
onPressed: ()async {
setState(() {
dbHelper.deleteDB();
var duration = new Duration(seconds: 8);
return new Timer(duration, (){
exitApp();
});
});
},
Future<bool> deleteDB() async {
try{
deleteDatabase(path);
}catch( e){
print(e.toString());
}
print('deleting db');
}
exitApp()async {
Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(builder: (context)=>login()),
(Route<dynamic> route) => false);
}
Future logInCheck(String name , String email, BuildContext buildContext) async
{
userModel user ;
final QuerySnapshot result = await userCollection.where('user_email', isEqualTo: email)
.where('user_name' , isEqualTo: name).limit(1).getDocuments(); // searching for a particular user
if(result.documents .length > 0){
final List<DocumentSnapshot> ds = result.documents;
for(int i=0; i< 1; i++ )
{
user = new userModel(ds[i].documentID, ds[i]['user_name'],ds[i]['user_email'],
ds[i]['user_gender'],
ds[i]['user_weight'],ds[i]['user_height'] ,ds[i]['cityPoint'] ,ds[i]['checkLogIn']);
print(user.user_email + ' : ' +user.user_id);
saveToSQFLiteDB(user);
print('Added');
}
nav.HOMEnavigate(buildContext,email);
} // if
else{
String msg = 'Couldnt find user with email \n fill with correct info' ;
nav.showSnackBar(buildContext , msg);
}
}
void saveToSQFLiteDB(userModel user) {
userInApp u = new userInApp(user.user_id, user.user_name, user.user_email, user.user_weight,
user.user_height, user.cityPoint.latitude, user.cityPoint.longitude,user.checkLogIN);
dbHelper.SAVE_USER(u);
}
Future<userInApp> SAVE_USER (userInApp user) async{
var dbClient = await datebase;
//user.user_id =
await dbClient.insert(userTable, user.toMap()).toString();
print('user has been saved');
return user;
}
I found the problem , I have to set db = null before deleting db , When I change deleteDB method to this , I t worked As I want .. Thanks
Future<void> deleteDB() async {
try{
print('deleting db');
db=null;
deleteDatabase(path);
}catch( e){
print(e.toString());
}
print('db is deleted');
}
I need to separate the json file data, I create a function to separate the character string but it returns single strings:
"AKERMI ## 1988",
"AKIM DE DUCOR ## 2005", ...
But I want to split this string into fields:
Name: AKERMI
Date: 1988
Name: AKIM DE DUCOR
Date: 2005
test.ts
getDataEtalon() {
return this.data.getEtalon().subscribe(
data => {
for (let key in data) {
this.etalon = data[key].split('##');
}
console.log(this.etalon);
},
err => {
console.log(err);
}
);
}
JSON
{
0: "AKERMI##1988",
5: "AKIM DE DUCOR##2005",
6: "AL FATIH##2003",
9: "AMER##1984",
13: "BELAMER##2004",
15: "CHAHATA##1990",
20: "CHARH##1999",
23: "CHEIKH EL ARAB##1990",
24: "DAHESS##1999",
35: "DARIKE##1991",
44: "DARMAN##1998",
50: "DAYJUR##1991",
51: "DJARNI DES FORGES##1995",
55: "DJELMANE##1999",
77: "DJOURDAN##1999",
83: "DORMANE##1984",
103: "FARADJALA##1993",
105: "GITPEN##1994",
110: "HAJJAM##1995",
175: "HAKIM DU BAC##1995",
180: "HALIM##1995",
185: "HAMID##1996",
194: "HAMZA##1995",
204: "HYRAM##1995",
206: "ISSAOUI##1996",
210: "JAMAK##1997",
213: "JEDEL##1997",
231: "JESROY DE CHAILLAC##1997",
232: "KAHLOUN##1998",
233: "KERBELLA##1992",
236: "LATHLETH##1999",
246: "MAJD AL ARAB##2002",
251: "MAKZAN##1991",
258: "MANGANELLO##1990",
259: "MANGUIER DE PIBOUL##1995",
263: "MAYSOUN##2000",
266: "MIGYESS##2000",
269: "MOUSSOUL##2000",
324: "MUNEEF##2001",
334: "NADIM##2001",
336: "NAKKACH##2001",
337: "NEDJAM LOTOIS##1996",
338: "NEMROD DU PAON##2001",
345: "NEZ D'OR##1997",
346: "NIZAM##1998",
348: "ORIENT EXPRESS##1995",
349: "OUAAD##2003",
350: "PHARAON DES CEDRES##2000",
351: "RAAD##2003",
357: "RAEEH##2003",
358: "RAFII##2003",
366: "ROUSHAAN##2003",
371: "SAMIR##1985",
391: "SARKI D'ESPIENS##1992",
392: "SAYAF##2004",
398: "SEMAOU'EL##2004",
400: "SOUR##1985",
404: "SULTAN AL BADR##2004",
405: "TIDJAM LOTOIS##1999",
433: "TOUWAYSSAN##1986",
434: "VENT DREDY##1992",
435: "VIOLET##2001",
436: "ZEIDOUN##1987"
}
data.map(car => {
let [name, year] = car.split('##');
return { name, year };
});
Will result in an array of objects with a name and a year
I have this function inside the main.c file which create a simple dialog made of check boxes and entries:
void compute_sha2 (GtkWidget *, struct hashWidget_t *);
void compute_sha3 (GtkWidget *, struct hashWidget_t *);
void compute_md5 (struct hashWidget_t *);
void compute_sha1 (struct hashWidget_t *);
void compute_gost94 (struct hashWidget_t *);
void compute_whirlpool (struct hashWidget_t *);
static void
compute_hash ( GtkWidget *fileDialog,
GtkWidget *mainwin,
const gchar *filename)
{
gtk_widget_hide (GTK_WIDGET (fileDialog));
struct hashWidget_t HashWidget;
gsize lenFilename = g_utf8_strlen (filename, -1);
HashWidget.filename = g_malloc (lenFilename + 1);
if (HashWidget.filename == NULL)
{
g_printerr ("Error during memory allocation\n");
return;
}
g_utf8_strncpy (HashWidget.filename, filename, lenFilename);
HashWidget.filename[lenFilename] = '\0';
gint i, result;
const gchar *label[] = {"MD5", "SHA-1", "SHA-256", "SHA3-256", "SHA512", "SHA3-512", "WHIRLPOOL", "GOST94"};
GtkWidget *contentArea, *grid, *dialog;
GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
PangoFontDescription *newFont = pango_font_description_new ();
pango_font_description_set_family (newFont, "monospace");
dialog = gtk_dialog_new_with_buttons ("Select Hash",
GTK_WINDOW (mainwin),
flags,
_("Cancel"), GTK_RESPONSE_REJECT,
NULL);
gtk_widget_set_size_request (dialog, 250, 150);
contentArea = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
for (i = 0; i < NUM_OF_HASH; i++)
{
HashWidget.hashCheck[i] = gtk_check_button_new_with_label (label[i]);
HashWidget.hashEntry[i] = gtk_entry_new ();
gtk_editable_set_editable (GTK_EDITABLE (HashWidget.hashEntry[i]), FALSE);
gtk_widget_override_font (GTK_WIDGET (HashWidget.hashEntry[i]), newFont);
}
pango_font_description_free (newFont);
grid = gtk_grid_new ();
gtk_grid_set_row_homogeneous (GTK_GRID (grid), TRUE);
gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
gtk_grid_set_row_spacing (GTK_GRID (grid), 5);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[0], 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[0], 2, 0, 6, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[1], 0, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[1], 2, 1, 6, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[2], 0, 2, 1, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[2], 2, 2, 6, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[3], 0, 3, 1, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[3], 2, 3, 6, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[4], 0, 4, 1, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[4], 2, 4, 6, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[5], 0, 5, 1, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[5], 2, 5, 6, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[6], 0, 6, 1, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[6], 2, 6, 6, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[7], 0, 7, 1, 1);
gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[7], 2, 7, 6, 1);
gtk_container_add (GTK_CONTAINER (contentArea), grid);
gtk_widget_show_all (dialog);
gtk_widget_set_name (GTK_WIDGET (HashWidget.hashCheck[2]), "BtSha256");
gtk_widget_set_name (GTK_WIDGET (HashWidget.hashCheck[3]), "BtSha3_256");
gtk_widget_set_name (GTK_WIDGET (HashWidget.hashCheck[4]), "BtSha512");
gtk_widget_set_name (GTK_WIDGET (HashWidget.hashCheck[5]), "BtSha3_512");
g_signal_connect_swapped (HashWidget.hashCheck[0], "clicked", G_CALLBACK (compute_md5), &HashWidget);
g_signal_connect_swapped (HashWidget.hashCheck[1], "clicked", G_CALLBACK (compute_sha1), &HashWidget);
g_signal_connect (HashWidget.hashCheck[2], "clicked", G_CALLBACK (compute_sha2), &HashWidget);
g_signal_connect (HashWidget.hashCheck[3], "clicked", G_CALLBACK (compute_sha3), &HashWidget);
g_signal_connect (HashWidget.hashCheck[4], "clicked", G_CALLBACK (compute_sha2), &HashWidget);
g_signal_connect (HashWidget.hashCheck[5], "clicked", G_CALLBACK (compute_sha3), &HashWidget);
g_signal_connect_swapped (HashWidget.hashCheck[6], "clicked", G_CALLBACK (compute_whirlpool), &HashWidget);
g_signal_connect_swapped (HashWidget.hashCheck[7], "clicked", G_CALLBACK (compute_gost94), &HashWidget);
result = gtk_dialog_run (GTK_DIALOG (dialog));
switch (result)
{
case GTK_RESPONSE_REJECT:
g_free (HashWidget.filename);
gtk_widget_destroy (dialog);
break;
}
}
The compute_* functions have the same codebase (except for sha2 and sha3 which have a 256/512 switch case):
static goffset get_file_size (const gchar *);
void
compute_sha3 ( GtkWidget *checkBt,
struct hashWidget_t *HashWidget)
{
gint bit;
if (g_strcmp0 (gtk_widget_get_name (checkBt), "BtSha3_256") == 0)
bit = 256;
else if (g_strcmp0 (gtk_widget_get_name (checkBt), "BtSha3_512") == 0)
bit = 512;
if (bit == 256)
{
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (HashWidget->hashCheck[3])))
{
gtk_entry_set_text (GTK_ENTRY (HashWidget->hashEntry[3]), "");
goto fine;
}
else if (g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (HashWidget->hashEntry[3])), -1) == 64)
goto fine;
}
else
{
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (HashWidget->hashCheck[5])))
{
gtk_entry_set_text (GTK_ENTRY (HashWidget->hashEntry[5]), "");
goto fine;
}
else if (g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (HashWidget->hashEntry[5])), -1) == 128)
goto fine;
}
guchar *digest;
gchar *hash;
GError *err = NULL;
gint fd, i, retVal;
goffset fileSize, doneSize = 0, diff = 0, offset = 0;
guint8 *fAddr;
struct sha3_256_ctx ctx256;
struct sha3_512_ctx ctx512;
if (bit == 256)
{
digest = g_malloc (SHA3_256_DIGEST_SIZE);
hash = g_malloc (65);
}
else
{
digest = g_malloc (SHA3_512_DIGEST_SIZE);
hash = g_malloc (129);
}
if (digest == NULL)
{
g_printerr ("sha2: error during memory allocation\n");
return;
}
if (hash == NULL)
{
g_printerr ("sha2: error during memory allocation\n");
g_free (digest);
return;
}
fd = g_open (HashWidget->filename, O_RDONLY | O_NOFOLLOW);
if (fd == -1)
{
g_printerr ("sha2: %s\n", g_strerror (errno));
return;
}
fileSize = get_file_size (HashWidget->filename);
if (bit == 256)
sha3_256_init (&ctx256);
else
sha3_512_init (&ctx512);
if (fileSize < BUF_FILE)
{
fAddr = mmap (NULL, fileSize, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0);
if (fAddr == MAP_FAILED)
{
g_printerr ("sha2: %s\n", g_strerror (errno));
g_free (digest);
g_free (hash);
g_close (fd, &err);
return;
}
if (bit == 256)
sha3_256_update (&ctx256, fileSize, fAddr);
else
sha3_512_update (&ctx512, fileSize, fAddr);
retVal = munmap (fAddr, fileSize);
if (retVal == -1)
{
g_printerr ("sha2: %s\n", g_strerror (errno));
g_free (digest);
g_free (hash);
g_close (fd, &err);
return;
}
goto nowhile;
}
while (fileSize > doneSize)
{
fAddr = mmap (NULL, BUF_FILE, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset);
if (fAddr == MAP_FAILED)
{
g_printerr ("sha2: %s\n", g_strerror (errno));
g_free (digest);
g_free (hash);
g_close (fd, &err);
return;
}
if (bit == 256)
sha3_256_update(&ctx256, BUF_FILE, fAddr);
else
sha3_512_update(&ctx512, BUF_FILE, fAddr);
doneSize += BUF_FILE;
diff = fileSize - doneSize;
offset += BUF_FILE;
if (diff < BUF_FILE && diff > 0)
{
fAddr = mmap (NULL, diff, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset);
if (fAddr == MAP_FAILED)
{
g_printerr ("sha2: %s\n", g_strerror (errno));
g_free (digest);
g_free (hash);
g_close (fd, &err);
return;
}
if (bit == 256)
sha3_256_update(&ctx256, diff, fAddr);
else
sha3_512_update(&ctx512, diff, fAddr);
retVal = munmap(fAddr, BUF_FILE);
if(retVal == -1){
g_printerr ("sha2: %s\n", g_strerror (errno));
g_free (digest);
g_free (hash);
g_close (fd, &err);
return;
}
break;
}
retVal = munmap(fAddr, BUF_FILE);
if(retVal == -1)
{
g_printerr ("sha2: %s\n", g_strerror (errno));
g_free (digest);
g_free (hash);
g_close (fd, &err);
return;
}
}
nowhile:
if (bit == 256)
{
sha3_256_digest(&ctx256, SHA3_256_DIGEST_SIZE, digest);
for(i=0; i<32; i++)
g_sprintf (hash+(i*2), "%02x", digest[i]);
hash[64] = '\0';
gtk_entry_set_text (GTK_ENTRY (HashWidget->hashEntry[3]), hash);
}
else
{
sha3_512_digest(&ctx512, SHA3_512_DIGEST_SIZE, digest);
for(i=0; i<64; i++)
g_sprintf (hash+(i*2), "%02x", digest[i]);
hash[128] = '\0';
gtk_entry_set_text (GTK_ENTRY (HashWidget->hashEntry[5]), hash);
}
g_close (fd, &err);
g_free (digest);
g_free (hash);
fine:
return;
}
static goffset
get_file_size (const gchar *filePath)
{
GFileInfo *info;
GFile *file;
GError *error = NULL;
const gchar *attributes = "standard::*";
GFileQueryInfoFlags flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS;
GCancellable *cancellable = NULL;
goffset fileSize;
file = g_file_new_for_path (filePath);
info = g_file_query_info (file, attributes, flags, cancellable, &error);
fileSize = g_file_info_get_size (info);
g_object_unref(file);
return fileSize;
}
The problem is that i'm getting a segfault when i'm trying to compute hashes (below there is the output of 3 segfault):
polcrypt[1678]: segfault at 7f48a40018d8 ip 00007f48e0ae9e8d sp 00007fff2ce02230 error 4 in libgtk-3.so.0.1200.2[7f48e08ac000+51a000]
gmain[1883]: segfault at 7f8814001b38 ip 00007f885f2a7f8b sp 00007f884ab1fc70 error 6 in libglib-2.0.so.0.4000.0[7f885f262000+130000]
polcrypt[1941]: segfault at 7f885c001b18 ip 00007f88868d045f sp 00007fffa35ddc60 error 7 in libglib-2.0.so.0.4000.0[7f888686c000+130000
Sometimes i got the segfault after 1 computation, sometimes after 3 and so on but what i have noticed is that the segfault occurs only when a file bigger than 10M is selected.
I think the problem is inside the main.c file because if i put a g_print at the end of the compute_* functions, the print statement is printed on the screen before getting the segfault.
I'm developing on Gentoo ~x64 and Fedora 20 both with GNOME 3.12, Glib 2.40, GCC 4.8 and libc-2.19
EDIT (core dump):
Reading symbols from polcrypt...(no debugging symbols found)...done.
[New LWP 8848]
[New LWP 8849]
[New LWP 8850]
[New LWP 8853]
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./polcrypt'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007f38888fada7 in g_slice_alloc () from /usr/lib64/libglib-2.0.so.0
and then the full bt:
(gdb) bt full
#0 0x00007f38888fada7 in g_slice_alloc () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#1 0x00007f38888b4d35 in g_array_sized_new () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#2 0x00007f388a4d181f in gtk_widget_path_new () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#3 0x00007f388a4cdc76 in _gtk_widget_create_path () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#4 0x00007f388a2f2820 in gtk_container_real_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#5 0x00007f388a2f7cb7 in gtk_container_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#6 0x00007f388a2b265d in gtk_box_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#7 0x00007f388a2f7cb7 in gtk_container_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#8 0x00007f388a2f2820 in gtk_container_real_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#9 0x00007f388a2f7cb7 in gtk_container_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#10 0x00007f388a4cdc0d in gtk_widget_get_path () from /usr/lib64/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
No symbol table info available.
#11 0x00007f388016d100 in adwaita_engine_render_focus () from /usr/lib64/gtk-3.0/3.0.0/theming-engines/libadwaita.so
No symbol table info available.
#12 0x00007f388a4293e1 in gtk_render_focus () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#13 0x00007f388a2e076c in gtk_check_button_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#14 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#15 0x00007f388a4bd4dd in gtk_widget_draw_marshallerv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#16 0x00007f3888bda53f in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#17 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#18 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#19 0x00007f388a4cad16 in _gtk_widget_draw_internal.part.62 () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#20 0x00007f388a4cc6eb in _gtk_widget_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
---Type <return> to continue, or q <return> to quit---
#21 0x00007f388a2f7abd in gtk_container_propagate_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#22 0x00007f388a2f7b82 in gtk_container_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#23 0x00007f388a3570a2 in gtk_grid_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#24 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#25 0x00007f388a4bd4dd in gtk_widget_draw_marshallerv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#26 0x00007f3888bda53f in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#27 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#28 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#29 0x00007f388a4cad16 in _gtk_widget_draw_internal.part.62 () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#30 0x00007f388a4cc6eb in _gtk_widget_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#31 0x00007f388a2f7abd in gtk_container_propagate_draw () from /usr/lib64/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
No symbol table info available.
#32 0x00007f388a2f7b82 in gtk_container_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#33 0x00007f388a2b4882 in gtk_box_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#34 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#35 0x00007f388a4bd4dd in gtk_widget_draw_marshallerv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#36 0x00007f3888bda53f in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#37 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#38 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#39 0x00007f388a4cad16 in _gtk_widget_draw_internal.part.62 () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#40 0x00007f388a4cc6eb in _gtk_widget_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#41 0x00007f388a2f7abd in gtk_container_propagate_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
---Type <return> to continue, or q <return> to quit---
#42 0x00007f388a2f7b82 in gtk_container_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#43 0x00007f388a4dd4a4 in gtk_window_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#44 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#45 0x00007f388a4bd4dd in gtk_widget_draw_marshallerv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#46 0x00007f3888bda5c7 in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#47 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#48 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#49 0x00007f388a4cad16 in _gtk_widget_draw_internal.part.62 () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#50 0x00007f388a4cc35f in _gtk_widget_draw_windows () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#51 0x00007f388a4cc5af in _gtk_widget_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#52 0x00007f388a4cc903 in gtk_widget_send_expose () from /usr/lib64/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
No symbol table info available.
#53 0x00007f388a392435 in gtk_main_do_event () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#54 0x00007f3889f8414b in _gdk_window_process_updates_recurse_helper () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#55 0x00007f3889f82545 in gdk_window_process_updates_internal () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#56 0x00007f3889f8266f in gdk_window_process_updates_with_mode () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#57 0x00007f3888bda5c7 in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#58 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#59 0x00007f3888bf4132 in g_signal_emit_by_name () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#60 0x00007f3889f7c8b0 in gdk_frame_clock_paint_idle () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#61 0x00007f3889f6ee68 in gdk_threads_dispatch () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#62 0x00007f38888e0283 in g_timeout_dispatch () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
---Type <return> to continue, or q <return> to quit---
#63 0x00007f38888df865 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#64 0x00007f38888dfbc8 in g_main_context_iterate.isra () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#65 0x00007f38888dfe8a in g_main_loop_run () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#66 0x00007f388a31a230 in gtk_dialog_run () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#67 0x000000000040a0be in compute_hash ()
No symbol table info available.
#68 0x000000000040871d in choose_file ()
No symbol table info available.
#69 0x00007f3888bda5c7 in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#70 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#71 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#72 0x00007f388a2bfacd in gtk_button_do_release () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#73 0x00007f388a2bfb13 in gtk_real_button_released () from /usr/lib64/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
No symbol table info available.
#74 0x00007f3888bda398 in g_closure_invoke () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#75 0x00007f3888beb467 in signal_emit_unlocked_R () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#76 0x00007f3888bf3939 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#77 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#78 0x00007f388a2bea31 in gtk_button_button_release () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#79 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#80 0x00007f3888bda5c7 in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#81 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#82 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#83 0x00007f388a4c0b54 in gtk_widget_event_internal () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
---Type <return> to continue, or q <return> to quit---
#84 0x00007f388a39093c in propagate_event () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#85 0x00007f388a3923b5 in gtk_main_do_event () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#86 0x00007f3889f9cc72 in gdk_event_source_dispatch () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#87 0x00007f38888df984 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#88 0x00007f38888dfbc8 in g_main_context_iterate.isra () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#89 0x00007f38888dfc6c in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#90 0x00007f3888ebe0ec in g_application_run () from /usr/lib64/libgio-2.0.so.0
No symbol table info available.
#91 0x00000000004082ff in main ()
No symbol table info available.
Problem found!
The munmap function in this snippet must take diff as length arg and not BUF_FILE.
if (diff < BUF_FILE && diff > 0)
{
fAddr = mmap (NULL, diff, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset);
retVal = munmap(fAddr, BUF_FILE); //wrong
retVal = munmap(fAddr, diff); //correct
break;
}