[libfreefare] 2 new revisions pushed by yob...@gmail.com on 2014-03-19 17:58 GMT

2 views
Skip to first unread message

libfr...@googlecode.com

unread,
Mar 19, 2014, 1:58:41 PM3/19/14
to nfc-tool...@googlegroups.com
master moved from c4e657f8cdf8 to 0ad6a09cdabb

2 new revisions:

Revision: 3e53c7811a3c
Author: Robert Clausecker <fuz...@gmail.com>
Date: Wed Mar 19 16:04:14 2014 UTC
Log: Check for NULL pointer in mifare_application_free()...
http://code.google.com/p/libfreefare/source/detail?r=3e53c7811a3c

Revision: 0ad6a09cdabb
Author: Robert Clausecker <fuz...@gmail.com>
Date: Wed Mar 19 17:20:38 2014 UTC
Log: Tell apart malloc failure from no application in
mifare_application_wr...
http://code.google.com/p/libfreefare/source/detail?r=0ad6a09cdabb

==============================================================================
Revision: 3e53c7811a3c
Author: Robert Clausecker <fuz...@gmail.com>
Date: Wed Mar 19 16:04:14 2014 UTC
Log: Check for NULL pointer in mifare_application_free()

This changeset alters the return type of mifare_application_free() from
void to
int. This change is necessary to be able to inform the caller whether the
call
to malloc() inside mifare_application_find() failed.

http://code.google.com/p/libfreefare/source/detail?r=3e53c7811a3c

Modified:
/libfreefare/freefare.h
/libfreefare/mifare_application.c

=======================================
--- /libfreefare/freefare.h Mon Jan 27 15:32:23 2014 UTC
+++ /libfreefare/freefare.h Wed Mar 19 16:04:14 2014 UTC
@@ -171,7 +171,7 @@
MifareClassicSectorNumber *mifare_application_alloc (Mad mad, const MadAid
aid, const size_t size);
ssize_t mifare_application_read (MifareTag tag, Mad mad, const MadAid
aid, void *buf, size_t nbytes, const MifareClassicKey key, const
MifareClassicKeyType key_type);
ssize_t mifare_application_write (MifareTag tag, Mad mad, const MadAid
aid, const void *buf, size_t nbytes, const MifareClassicKey key, const
MifareClassicKeyType key_type);
-void mifare_application_free (Mad mad, const MadAid aid);
+int mifare_application_free (Mad mad, const MadAid aid);

MifareClassicSectorNumber *mifare_application_find (Mad mad, const MadAid
aid);

=======================================
--- /libfreefare/mifare_application.c Tue Aug 24 10:51:58 2010 UTC
+++ /libfreefare/mifare_application.c Wed Mar 19 16:04:14 2014 UTC
@@ -159,18 +159,24 @@
/*
* Remove an application from a MAD.
*/
-void
+int
mifare_application_free (Mad mad, MadAid aid)
{
MifareClassicSectorNumber *sectors = mifare_application_find (mad,
aid);
MifareClassicSectorNumber *p = sectors;
MadAid free_aid = { 0x00, 0x00 };
+
+ /* figure out if malloc() in mifare_application_find() failed */
+ if (sectors == NULL) return count_aids (mad, aid) ? -1 : 0;
+
while (*p) {
mad_set_aid (mad, *p, free_aid);
p++;
}

free (sectors);
+
+ return 0;
}



==============================================================================
Revision: 0ad6a09cdabb
Author: Robert Clausecker <fuz...@gmail.com>
Date: Wed Mar 19 17:20:38 2014 UTC
Log: Tell apart malloc failure from no application in
mifare_application_write()

http://code.google.com/p/libfreefare/source/detail?r=0ad6a09cdabb

Modified:
/libfreefare/mifare_application.c

=======================================
--- /libfreefare/mifare_application.c Wed Mar 19 16:04:14 2014 UTC
+++ /libfreefare/mifare_application.c Wed Mar 19 17:20:38 2014 UTC
@@ -267,8 +267,11 @@
MifareClassicSectorNumber *sectors = mifare_application_find (mad,
aid);
MifareClassicSectorNumber *s = sectors;

- if (!sectors)
- return errno = EBADF, -1;
+ if (!sectors) {
+ /* mifare_application_find may also fail if malloc() fails */
+ if (errno != ENOMEM) errno = EBADF;
+ return -1;
+ }

while (*s && nbytes && (res >= 0)) {
MifareClassicBlockNumber first_block = mifare_classic_sector_first_block
(*s);
Reply all
Reply to author
Forward
0 new messages