Skip to content

Commit 870db92

Browse files
committed
Merge branch 'master' into bug-esp8266#3795
2 parents dc90f97 + 7de58d9 commit 870db92

File tree

18 files changed

+732
-100
lines changed

18 files changed

+732
-100
lines changed

cores/esp8266/Arduino.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void ets_intr_unlock();
178178
#define _NOP() do { __asm__ volatile ("nop"); } while (0)
179179
#endif
180180

181-
typedef unsigned int word;
181+
typedef uint16_t word;
182182

183183
#define bit(b) (1UL << (b))
184184
#define _BV(b) (1UL << (b))

cores/esp8266/Schedule.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,6 @@ static scheduled_fn_t* sLastUnused = 0;
1414

1515
static int sCount = 0;
1616

17-
static void init_lists() __attribute__((unused));
18-
static void init_lists()
19-
{
20-
if (sCount != 0) {
21-
return;
22-
}
23-
while (sCount < SCHEDULED_FN_INITIAL_COUNT) {
24-
scheduled_fn_t* it = new scheduled_fn_t;
25-
if (sCount == 0) {
26-
sFirstUnused = it;
27-
}
28-
else {
29-
sLastUnused->mNext = it;
30-
}
31-
sLastUnused = it;
32-
++sCount;
33-
}
34-
sLastUnused->mNext = NULL;
35-
}
36-
3717
static scheduled_fn_t* get_fn() {
3818
scheduled_fn_t* result = NULL;
3919
// try to get an item from unused items list

cores/esp8266/WString.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,33 @@ unsigned char String::equalsIgnoreCase(const String &s2) const {
477477
return 1;
478478
}
479479

480+
unsigned char String::equalsConstantTime(const String &s2) const {
481+
// To avoid possible time-based attacks present function
482+
// compares given strings in a constant time.
483+
if(len != s2.len)
484+
return 0;
485+
//at this point lengths are the same
486+
if(len == 0)
487+
return 1;
488+
//at this point lenghts are the same and non-zero
489+
const char *p1 = buffer;
490+
const char *p2 = s2.buffer;
491+
unsigned int equalchars = 0;
492+
unsigned int diffchars = 0;
493+
while(*p1) {
494+
if(*p1 == *p2)
495+
++equalchars;
496+
else
497+
++diffchars;
498+
++p1;
499+
++p2;
500+
}
501+
//the following should force a constant time eval of the condition without a compiler "logical shortcut"
502+
unsigned char equalcond = (equalchars == len);
503+
unsigned char diffcond = (diffchars == 0);
504+
return (equalcond & diffcond); //bitwise AND
505+
}
506+
480507
unsigned char String::startsWith(const String &s2) const {
481508
if(len < s2.len)
482509
return 0;

cores/esp8266/WString.h

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class String {
194194
unsigned char operator <=(const String &rhs) const;
195195
unsigned char operator >=(const String &rhs) const;
196196
unsigned char equalsIgnoreCase(const String &s) const;
197+
unsigned char equalsConstantTime(const String &s) const;
197198
unsigned char startsWith(const String &prefix) const;
198199
unsigned char startsWith(const String &prefix, unsigned int offset) const;
199200
unsigned char endsWith(const String &suffix) const;

cores/esp8266/coredecls.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
#ifndef __COREDECLS_H
3+
#define __COREDECLS_H
4+
5+
extern bool s_bootTimeSet;
6+
7+
// TODO: put declarations here, get rid of -Wno-implicit-function-declaration
8+
9+
#endif // __COREDECLS_H

0 commit comments

Comments
 (0)