mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-13 17:00:19 +00:00
Fix mg_random
This commit is contained in:
1 parent
a3f8f33d50
commit
41f5daeb47
3 files changed
+8
-27
No files matched your search
+4
-13
@@ -1099,7 +1099,6 @@ void mg_http_serve_dir(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
size_t n1 = strlen(t1), n2;
|
size_t n1 = strlen(t1), n2;
|
||||||
|
|
||||||
mg_url_decode(hm->uri.ptr, hm->uri.len, t1 + n1, sizeof(t1) - n1, 0);
|
mg_url_decode(hm->uri.ptr, hm->uri.len, t1 + n1, sizeof(t1) - n1, 0);
|
||||||
LOG(LL_DEBUG, ("SERVE: [%s]", t1 + n1));
|
|
||||||
t1[sizeof(t1) - 1] = '\0';
|
t1[sizeof(t1) - 1] = '\0';
|
||||||
n2 = strlen(t1);
|
n2 = strlen(t1);
|
||||||
while (n2 > 0 && t1[n2 - 1] == '/') t1[--n2] = 0;
|
while (n2 > 0 && t1[n2 - 1] == '/') t1[--n2] = 0;
|
||||||
@@ -3887,19 +3886,11 @@ bool mg_file_printf(const char *path, const char *fmt, ...) {
|
|||||||
void mg_random(void *buf, size_t len) {
|
void mg_random(void *buf, size_t len) {
|
||||||
bool done = false;
|
bool done = false;
|
||||||
#if MG_ENABLE_FS
|
#if MG_ENABLE_FS
|
||||||
if (!done) {
|
FILE *fp = mg_fopen("/dev/urandom", "rb");
|
||||||
FILE *fp = mg_fopen("/dev/urandom", "rb");
|
if (fp != NULL) {
|
||||||
if (fp != NULL) {
|
fread(buf, 1, len, fp);
|
||||||
fread(buf, 1, len, fp);
|
fclose(fp);
|
||||||
fclose(fp);
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if MG_ENABLE_MBEDTLS
|
|
||||||
if (!done && mbedtls_entropy_func(NULL, buf, len) == 0) {
|
|
||||||
done = true;
|
done = true;
|
||||||
LOG(LL_DEBUG, ("RAND %d", done));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!done) {
|
if (!done) {
|
||||||
|
|||||||
@@ -679,7 +679,6 @@ void mg_http_serve_dir(struct mg_connection *c, struct mg_http_message *hm,
|
|||||||
size_t n1 = strlen(t1), n2;
|
size_t n1 = strlen(t1), n2;
|
||||||
|
|
||||||
mg_url_decode(hm->uri.ptr, hm->uri.len, t1 + n1, sizeof(t1) - n1, 0);
|
mg_url_decode(hm->uri.ptr, hm->uri.len, t1 + n1, sizeof(t1) - n1, 0);
|
||||||
LOG(LL_DEBUG, ("SERVE: [%s]", t1 + n1));
|
|
||||||
t1[sizeof(t1) - 1] = '\0';
|
t1[sizeof(t1) - 1] = '\0';
|
||||||
n2 = strlen(t1);
|
n2 = strlen(t1);
|
||||||
while (n2 > 0 && t1[n2 - 1] == '/') t1[--n2] = 0;
|
while (n2 > 0 && t1[n2 - 1] == '/') t1[--n2] = 0;
|
||||||
|
|||||||
+4
-13
@@ -88,20 +88,11 @@ bool mg_file_printf(const char *path, const char *fmt, ...) {
|
|||||||
void mg_random(void *buf, size_t len) {
|
void mg_random(void *buf, size_t len) {
|
||||||
bool done = false;
|
bool done = false;
|
||||||
#if MG_ENABLE_FS
|
#if MG_ENABLE_FS
|
||||||
if (!done) {
|
FILE *fp = mg_fopen("/dev/urandom", "rb");
|
||||||
FILE *fp = mg_fopen("/dev/urandom", "rb");
|
if (fp != NULL) {
|
||||||
if (fp != NULL) {
|
fread(buf, 1, len, fp);
|
||||||
fread(buf, 1, len, fp);
|
fclose(fp);
|
||||||
fclose(fp);
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if MG_ENABLE_MBEDTLS
|
|
||||||
extern int mbedtls_entropy_func(void *, void *, size_t);
|
|
||||||
if (!done && mbedtls_entropy_func(NULL, buf, len) == 0) {
|
|
||||||
done = true;
|
done = true;
|
||||||
LOG(LL_DEBUG, ("RAND %d", done));
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!done) {
|
if (!done) {
|
||||||
|
|||||||
Reference in new issue
Block a user