-rw-r--r-- | noncore/apps/opie-reader/Bkmks.cpp | 1 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/Excel.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/zsafe/zsafe.cpp | 57 |
3 files changed, 33 insertions, 29 deletions
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp index 00141a3..45aa045 100644 --- a/noncore/apps/opie-reader/Bkmks.cpp +++ b/noncore/apps/opie-reader/Bkmks.cpp | |||
@@ -338,16 +338,17 @@ Bkmk* BkmkFile::read05(BkmkFile* /*_this*/, FILE* f) | |||
338 | nm[ln] = 0; | 338 | nm[ln] = 0; |
339 | fread(&ln,sizeof(ln),1,f); | 339 | fread(&ln,sizeof(ln),1,f); |
340 | tchar* anno = new tchar[ln+1]; | 340 | tchar* anno = new tchar[ln+1]; |
341 | if (ln > 0) fread(anno,sizeof(tchar),ln,f); | 341 | if (ln > 0) fread(anno,sizeof(tchar),ln,f); |
342 | anno[ln] = 0; | 342 | anno[ln] = 0; |
343 | unsigned int pos; | 343 | unsigned int pos; |
344 | fread(&pos,sizeof(pos),1,f); | 344 | fread(&pos,sizeof(pos),1,f); |
345 | b = new Bkmk(nm,anno,pos); | 345 | b = new Bkmk(nm,anno,pos); |
346 | delete [] anno; | ||
346 | } | 347 | } |
347 | } | 348 | } |
348 | return b; | 349 | return b; |
349 | } | 350 | } |
350 | 351 | ||
351 | Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f) | 352 | Bkmk* BkmkFile::read06(BkmkFile* /*_this*/, FILE* f) |
352 | { | 353 | { |
353 | Bkmk* b = NULL; | 354 | Bkmk* b = NULL; |
diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp index 51fe707..27080e9 100644 --- a/noncore/apps/opie-sheet/Excel.cpp +++ b/noncore/apps/opie-sheet/Excel.cpp | |||
@@ -372,17 +372,19 @@ ExcelBREC* ExcelBook::PeekBREC(void) | |||
372 | SeekPosition(oldpos); | 372 | SeekPosition(oldpos); |
373 | return NextRec; | 373 | return NextRec; |
374 | }; | 374 | }; |
375 | 375 | ||
376 | char* ExcelBook::GetDataOfBREC(ExcelBREC* record) | 376 | char* ExcelBook::GetDataOfBREC(ExcelBREC* record) |
377 | { | 377 | { |
378 | if(record->data==NULL) | 378 | if(record->data==NULL) |
379 | { | 379 | { |
380 | ConvertCharToArray(record,Read(record->position,record->length),record->length); | 380 | char* readData = Read(record->position,record->length); |
381 | ConvertCharToArray(record,readData,record->length); | ||
382 | delete [] readData; | ||
381 | }; | 383 | }; |
382 | return record->data;//new? | 384 | return record->data;//new? |
383 | }; | 385 | }; |
384 | 386 | ||
385 | void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) | 387 | void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) |
386 | { | 388 | { |
387 | record->data=new char[length]; | 389 | record->data=new char[length]; |
388 | for(int w1=0;w1<=length-1;w1++) | 390 | for(int w1=0;w1<=length-1;w1++) |
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp index f70f863..9c0c6ce 100644 --- a/noncore/apps/zsafe/zsafe.cpp +++ b/noncore/apps/zsafe/zsafe.cpp | |||
@@ -1763,38 +1763,42 @@ int ZSafe::loadInit(const char* _filename, const char *password) | |||
1763 | int count=0, count2=0, count3=0; | 1763 | int count=0, count2=0, count3=0; |
1764 | unsigned char charbuf[8]; | 1764 | unsigned char charbuf[8]; |
1765 | unsigned short ciphertext[4]; | 1765 | unsigned short ciphertext[4]; |
1766 | char key[128]; | 1766 | char key[128]; |
1767 | Krc2* krc2 = new Krc2(); | 1767 | Krc2* krc2 = new Krc2(); |
1768 | 1768 | ||
1769 | fd = fopen (_filename, "rb"); | 1769 | fd = fopen (_filename, "rb"); |
1770 | 1770 | ||
1771 | QFileInfo f (_filename); | 1771 | QFileInfo f (_filename); |
1772 | load_buffer_length = f.size(); | 1772 | load_buffer_length = f.size(); |
1773 | load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; | 1773 | load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; |
1774 | 1774 | ||
1775 | if (fd == NULL) | 1775 | if (fd == NULL) { |
1776 | delete krc2; | ||
1776 | return PWERR_OPEN; | 1777 | return PWERR_OPEN; |
1778 | } | ||
1777 | 1779 | ||
1778 | buffer = (char *)malloc(load_buffer_length); | 1780 | buffer = (char *)malloc(load_buffer_length); |
1779 | for (j = 0; password[j] != '\0'; j++) { | 1781 | for (j = 0; password[j] != '\0'; j++) { |
1780 | key[j] = password[j]; | 1782 | key[j] = password[j]; |
1781 | } | 1783 | } |
1782 | keylength = j; | 1784 | keylength = j; |
1783 | krc2->rc2_expandkey (key, keylength, 128); | 1785 | krc2->rc2_expandkey (key, keylength, 128); |
1784 | 1786 | ||
1785 | #ifndef Q_WS_WIN | 1787 | #ifndef Q_WS_WIN |
1786 | size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); | 1788 | size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); |
1787 | #else | 1789 | #else |
1788 | size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); | 1790 | size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); |
1789 | #endif | 1791 | #endif |
1790 | 1792 | ||
1791 | if (size < 8) | 1793 | if (size < 8) { |
1794 | delete krc2; | ||
1792 | return PWERR_DATA; | 1795 | return PWERR_DATA; |
1796 | } | ||
1793 | 1797 | ||
1794 | for (count = 0; count < 4; count++) { | 1798 | for (count = 0; count < 4; count++) { |
1795 | count2 = count << 1; | 1799 | count2 = count << 1; |
1796 | iv[count] = charbuf[count2] << 8; | 1800 | iv[count] = charbuf[count2] << 8; |
1797 | iv[count] += charbuf[count2 + 1]; | 1801 | iv[count] += charbuf[count2 + 1]; |
1798 | } | 1802 | } |
1799 | 1803 | ||
1800 | size = 0; | 1804 | size = 0; |
@@ -1804,16 +1808,17 @@ int ZSafe::loadInit(const char* _filename, const char *password) | |||
1804 | while (count < 8) { | 1808 | while (count < 8) { |
1805 | count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); | 1809 | count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); |
1806 | #else | 1810 | #else |
1807 | while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { | 1811 | while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { |
1808 | while (count < 8) { | 1812 | while (count < 8) { |
1809 | count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); | 1813 | count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); |
1810 | #endif | 1814 | #endif |
1811 | if (count2 == 0) { | 1815 | if (count2 == 0) { |
1816 | delete krc2; | ||
1812 | return PWERR_DATA; | 1817 | return PWERR_DATA; |
1813 | } | 1818 | } |
1814 | count += count2; | 1819 | count += count2; |
1815 | } /* while (count < 8) */ | 1820 | } /* while (count < 8) */ |
1816 | 1821 | ||
1817 | size += 8; | 1822 | size += 8; |
1818 | for (count2 = 0; count2 < 8; count2 += 2) { | 1823 | for (count2 = 0; count2 < 8; count2 += 2) { |
1819 | count3 = count2 >> 1; | 1824 | count3 = count2 >> 1; |
@@ -1824,16 +1829,17 @@ int ZSafe::loadInit(const char* _filename, const char *password) | |||
1824 | iv[count3] = plaintext[count3]; | 1829 | iv[count3] = plaintext[count3]; |
1825 | } /* for (count2) */ | 1830 | } /* for (count2) */ |
1826 | 1831 | ||
1827 | krc2->rc2_decrypt (plaintext); | 1832 | krc2->rc2_decrypt (plaintext); |
1828 | memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); | 1833 | memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); |
1829 | bufferIndex += 8; | 1834 | bufferIndex += 8; |
1830 | buffer[bufferIndex + 1] = '\0'; | 1835 | buffer[bufferIndex + 1] = '\0'; |
1831 | } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ | 1836 | } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ |
1837 | delete krc2; | ||
1832 | size -= buffer[size - 1]; | 1838 | size -= buffer[size - 1]; |
1833 | lastcount = 0; | 1839 | lastcount = 0; |
1834 | 1840 | ||
1835 | /* This will point to the starting index */ | 1841 | /* This will point to the starting index */ |
1836 | bufferIndex = 0; | 1842 | bufferIndex = 0; |
1837 | return PWERR_GOOD; | 1843 | return PWERR_GOOD; |
1838 | } | 1844 | } |
1839 | 1845 | ||
@@ -2094,47 +2100,35 @@ int ZSafe::saveInit(const char *_filename, const char *password) | |||
2094 | { | 2100 | { |
2095 | char key[128]; | 2101 | char key[128]; |
2096 | unsigned int j = 0; | 2102 | unsigned int j = 0; |
2097 | unsigned int keylength; | 2103 | unsigned int keylength; |
2098 | // int val; | 2104 | // int val; |
2099 | int count2; | 2105 | int count2; |
2100 | Krc2* krc2 = new Krc2(); | 2106 | Krc2* krc2 = new Krc2(); |
2101 | 2107 | ||
2102 | /* first we should check the permissions of the filename */ | 2108 | QFileInfo f (_filename); |
2103 | /* | 2109 | save_buffer_length = f.size(); |
2104 | if (QFile::exists(_filename)) { | 2110 | save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; |
2105 | val = checkFile(_filename); | ||
2106 | if (val != PWERR_GOOD) | ||
2107 | return val; | ||
2108 | } else | ||
2109 | { | ||
2110 | val = creat (_filename, (S_IRUSR | S_IWUSR)); | ||
2111 | if (val == -1) | ||
2112 | return PWERR_OPEN; | ||
2113 | else | ||
2114 | close(val); | ||
2115 | } | ||
2116 | */ | ||
2117 | QFileInfo f (_filename); | ||
2118 | save_buffer_length = f.size(); | ||
2119 | save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; | ||
2120 | 2111 | ||
2121 | fd = fopen (_filename, "wb"); | 2112 | fd = fopen (_filename, "wb"); |
2122 | if (fd == NULL) | 2113 | if (fd == NULL) { |
2114 | delete krc2; | ||
2123 | return PWERR_OPEN; | 2115 | return PWERR_OPEN; |
2116 | } | ||
2124 | 2117 | ||
2125 | buffer = (char*)malloc(save_buffer_length); | 2118 | buffer = (char*)malloc(save_buffer_length); |
2126 | 2119 | ||
2127 | /* make the key ready */ | 2120 | /* make the key ready */ |
2128 | for (j = 0; password[j] != '\0'; j++) { | 2121 | for (j = 0; password[j] != '\0'; j++) { |
2129 | key[j] = password[j]; | 2122 | key[j] = password[j]; |
2130 | } | 2123 | } |
2131 | keylength = j; | 2124 | keylength = j; |
2132 | krc2->rc2_expandkey (key, keylength, 128); | 2125 | krc2->rc2_expandkey (key, keylength, 128); |
2126 | delete krc2; | ||
2133 | 2127 | ||
2134 | /* First, we make the IV */ | 2128 | /* First, we make the IV */ |
2135 | for (count2 = 0; count2 < 4; count2++) { | 2129 | for (count2 = 0; count2 < 4; count2++) { |
2136 | iv[count2] = rand (); | 2130 | iv[count2] = rand (); |
2137 | putc ((unsigned char) (iv[count2] >> 8), fd); | 2131 | putc ((unsigned char) (iv[count2] >> 8), fd); |
2138 | putc ((unsigned char) (iv[count2] & 0xff), fd); | 2132 | putc ((unsigned char) (iv[count2] & 0xff), fd); |
2139 | } | 2133 | } |
2140 | 2134 | ||
@@ -2183,25 +2177,31 @@ int ZSafe::saveEntry(char *entry[FIELD_SIZE]) | |||
2183 | for (count3 = 0; count3 < 4; count3++) { | 2177 | for (count3 = 0; count3 < 4; count3++) { |
2184 | ciphertext[count3] = iv[count3] ^ plaintext[count3]; | 2178 | ciphertext[count3] = iv[count3] ^ plaintext[count3]; |
2185 | 2179 | ||
2186 | /* Now store the ciphertext as the iv */ | 2180 | /* Now store the ciphertext as the iv */ |
2187 | iv[count3] = plaintext[count3]; | 2181 | iv[count3] = plaintext[count3]; |
2188 | 2182 | ||
2189 | /* reset the buffer index */ | 2183 | /* reset the buffer index */ |
2190 | bufferIndex = 0; | 2184 | bufferIndex = 0; |
2191 | if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; | 2185 | if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) { |
2192 | if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; | 2186 | delete krc2; |
2187 | return PWERR_DATA; | ||
2188 | } | ||
2189 | if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) { | ||
2190 | delete krc2; | ||
2191 | return PWERR_DATA; | ||
2192 | } | ||
2193 | } /*for (count3 = 0; count3 < 5; count3++)*/ | 2193 | } /*for (count3 = 0; count3 < 5; count3++)*/ |
2194 | } /*if (bufferIndex == 5)*/ | 2194 | } /*if (bufferIndex == 5)*/ |
2195 | /* increment a short, not a byte */ | 2195 | /* increment a short, not a byte */ |
2196 | count2 += 2; | 2196 | count2 += 2; |
2197 | } /*while (count2 < strlen (buffer))*/ | 2197 | } /*while (count2 < strlen (buffer))*/ |
2198 | int ret = PWERR_GOOD; | 2198 | delete krc2; |
2199 | return ret; | 2199 | return PWERR_GOOD; |
2200 | } | 2200 | } |
2201 | 2201 | ||
2202 | int ZSafe::saveFinalize(void) | 2202 | int ZSafe::saveFinalize(void) |
2203 | { | 2203 | { |
2204 | int count1, retval = PWERR_GOOD; | 2204 | int count1, retval = PWERR_GOOD; |
2205 | unsigned short ciphertext[4]; | 2205 | unsigned short ciphertext[4]; |
2206 | Krc2* krc2 = new Krc2(); | 2206 | Krc2* krc2 = new Krc2(); |
2207 | 2207 | ||
@@ -2223,16 +2223,17 @@ int ZSafe::saveFinalize(void) | |||
2223 | for (count1 = 0; count1 < 4; count1++) { | 2223 | for (count1 = 0; count1 < 4; count1++) { |
2224 | ciphertext[count1] = iv[count1] ^ plaintext[count1]; | 2224 | ciphertext[count1] = iv[count1] ^ plaintext[count1]; |
2225 | if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; | 2225 | if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; |
2226 | if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; | 2226 | if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; |
2227 | } | 2227 | } |
2228 | 2228 | ||
2229 | fclose (fd); | 2229 | fclose (fd); |
2230 | free(buffer); | 2230 | free(buffer); |
2231 | delete krc2; | ||
2231 | return retval; | 2232 | return retval; |
2232 | } | 2233 | } |
2233 | 2234 | ||
2234 | void ZSafe::quitMe () | 2235 | void ZSafe::quitMe () |
2235 | { | 2236 | { |
2236 | if (modified) | 2237 | if (modified) |
2237 | { | 2238 | { |
2238 | switch( QMessageBox::information( this, tr("ZSafe"), | 2239 | switch( QMessageBox::information( this, tr("ZSafe"), |