Ubuntu 18.04 micro sd card locked readonly

I am running Ubuntu 18.04 on one desktop, and Windows 10 (19 something the latest version), on an old Dell Vostro-220 on another desktop. The mission is to flash an android OS onto a micro SD card for use in a Raspberry Pi 3B.

The SD card is a Samsung 32 Evo+ that has the Raspbian Stretch OS on it and the Pi works fine. I powered off the Pi and removed the Samsung SD card. I had the downloaded Android OS in a folder in my Dowloads directory. I plugged the card into an adapter (that has NO readolny switch), into the Ubuntu desktop. The card is found and the files are readable.

I am using Etcher to flash the OS onto the SD card. Etcher shows the card as “Locked”. The card is locked in a readonly state

I can not remove the folders, format, delete the partition, or write to the micro SD card. I tried:

  • gparted
  • disks
  • parted
  • guidus
  • dd commands
  • Changing permissions and ownership
  • disk manager in Windows
  • diskpart in windows
  • formatting in my Samsung Galaxy phone
  • maybe a few more “fixes” I can’t remember

Nothing has worked. I have created a ticket at Samsung but there is no one in customer service today, Saturday. Then I tried another used 32 gig mirco SD card that I had taken out of an old phone. I got the same result. I thought maybe because it was formatted in a phone that it was locked in readonly.

So I plugged in a brand new micro SD card. I opened Etcher to flash the Android OS to the brand new, never used, just out of the package, micro SD card, that has no switch, and got the same result. Etcher says the SD card is locked. It is in “readonly”. Nothing I have tried can make it writable. Three different cards, three different brands, 1 new, 2 used (but working fine before), I plugged them into the 18.04 desktop.

I have spent several hours searching for a solution, and tried many things. Has anyone actually solved this problem? Please advise.

when i modify etc/security/limits.conf for ubuntu 16.04 ive got E45: ‘readonly’ option is set (add ! to override)

I’M trying to increase the open files limit for ubuntu 16.04 version by using vi /etc/security/limits.conf then I add two lines like

* soft nofile 4096

* hard nofile 4096

but when ─▒ use ­čśí to save and exit i’ve got E45: ‘readonly’ option is set (add ! to override) and it doesn’t exit

Lightweight read-only string implementation (C++) [on hold]

In C++ currently we have few possibilities to work with strings:

1) by using plain old C-strings — unfortunately, we have penalty for getting length of string each time, and we should manually control life time of array, which actually contains data…

2) we can use std::string, but again, unfortunately this is not very efficient class: it’s relatively large (32 bytes on 64-bit platform) and it always copyes data;

3) modern C++ gives new opportunity: std::string_view class, which is quite effective, but unfortunately it doesn’t own strings, on which it references: again we should control life time of the containers in which strings really stored.

In Java or C# we have more reasonable solution, when class implementing strings divided on two:

  • StringBuilder which behaves like std::string and can be used to construct and edit strings;

  • String which is lightweight and always readonly, and can be used to access previously created strings — this class can be stored in arrays, passed in functions, etc…

I think, same solution might be perfect for C++, but this requires lot of work…

I want to present solution, which behaves like string in C# (in sence, that it is readonly and only can be created and reassigned). No counterpart, like StringBuffer was created, but my solution has very basic functions to create new strings.

I want to see some comments about my solution and suggestions how can I improve it.

Basic requirements when I design my own string-class implementation was following:

  • it should be very lightweight;

  • copying and passing by value should be almost free;

  • multiple intances of same string should share it’s representation (and memory);

  • strings cant be created from string literals and shouldn’t require memory allocation or copying in that case;

  • strings should be freely convertible to/from string_view class.

You can see the code here: https://coliru.stacked-crooked.com/a/ba8b05b14dbfbc52

#include <new> #include <string_view> #include <atomic> #include <stdexcept> #include <stdarg.h>  // Some implementation of class similar to `string_view' should be available in global namespace // (CString class requires this) using std::string_view;   // Class `CString' implements lightweight constant read-only string suitable // for storing in arrays, for passing by value, etc... // // Main essential properties of `CString' class are following: // //    * it has extremelly small size (1 pointer); // //    * copying (and passing by value) is almost free of cost; // //    * multiple instances of CString can share internal representation; // //    * if CString created from string literal it doesn't require //      neither memory allocation, nor data copying (so constant strings //      are really weightless). // // Some negative properties: // //    * size of stored string limited to 65536 bytes; // //    * nul-symbol can't be stored inside string; // //    * program can crash in runtime when constructing CString from string literal, //      if .rodata segment is larger than 8 MBytes (this is limit for 32-bit platform, //      for 64-bit platform limit is hardly noticeable); // //    * computing string size, when string was created from string literal and size //      is larger than 128 bytes, isn't performed in constant time: for each next //      128 bytes small additional penalty added (so computing size of large string //      created from string literals isn't free). // // This class can be modified, it represents only read-only strings, and can be // created in one of the following ways: // //    1) from literal string: CString text("some text..."); // //    2) from `string_view' and from const char* (implicitly, via string_view); // //    3) as result of calling static printf-like functions `printf' and `vprintf'; // //    4) as result of concatenation of any string-like objects convertible to string_view, //       via static concat(...) function; // //    5) as result of calling constructor with specifying desired string size and //       initializer function, which then creates string contents. // // CString class supports following operations: // //    * strings can be reassigned (but not modified); // //    * conversion to C-string or string_view (CString always stores zero-terminated //      representation of the string, nul-symbol can't be stored in the string); // //    * size of the string computed in constant time for most practical cases (see note above); // //    * characters can be accessed by index (implemented operator[]). // class CString { public:     typedef unsigned short size_type;  // first major limit: string sizes  private:     // This structure contains shared representation of the string, when string      // is stored in allocated memory.     struct Shared     {         std::atomic<unsigned short> count;  // second major limit: the number of shared copies         const size_type  size;              // size of the string (not including terminating zero)         char             data[1];          Shared(size_type size) : count{1}, size{size} {}     };      // This constant determines how many bits of variable `ptr' used for storing offset     // from `Base' to string literal, and how many bits used for encoding string literal length.     // Actually for string length ConstSizeBits-1 bits used (only lower bits of the length are     // stored, upper bits restored in runtime).     constexpr static const unsigned ConstSizeBits = 8;      // Address of this variable used to compute offset in .rodata segment, for storing string literals.     static const char Base[1];      // this variable might contain one of the three variants:     //     1) nullptr -- when CString contains empty string;     //     2) pointer to struct Shared -- when CString holds string in allocated memory;     //     3) offset between `Base' and string literal (offset in .rodata segment)     //        combined with lowest 7 bits of string length.     intptr_t ptr;      // returns `true' if current instance of CString stores string literal.     bool is_const() const noexcept        { return ptr & 1; }      Shared *get_shared() const noexcept   { return reinterpret_cast<Shared*>(ptr); }      // returns string literal address from offset stored in `ptr'     const char* const_data() const noexcept     {         intptr_t offset = ptr >> ConstSizeBits;         return reinterpret_cast<const char*>(offset + Base);     }      // function called in case, when offset can't be encoded in `ptr' (when offset is too large)     __attribute__((noreturn, noinline))     void runtime_error(const char *msg) const     {         throw std::runtime_error(msg);     }  public:     // create empty string (no memory allocation)     CString() noexcept : ptr{0} {}      // create string with specified size and initialize it by given functior (memory allocated)     template <typename Initializer> CString(size_t size, Initializer init)     {         if (!size) new (this) CString;         else {             if (size > size_type(-1))                 runtime_error("CString overflow");              Shared *shared = static_cast<Shared*>(operator new(size + sizeof(Shared)));             new (shared) Shared(size_type(size));             init(shared->data);             shared->data[size] = 0;             ptr = intptr_t(shared);         }     }      // create string from string_view class (memory allocated and string copy created)     explicit CString(string_view str)     {         new (this) CString(str.size(), [&str](char *data){ str.copy(data, str.size()); });     }      // Note: constructor like CString(const char *str) and operator= with same argument     // not implemented intentionally -- string should be created or assigned via intermediate     // string_view class. Existence of constructor or assigne operator with "const char *"     // argument prevents implementation of constructor or assign operators wich works with     // string literals (see below).      // create constant string from string literal (i.e. CString const_string("text")...)     // memory will not be allocated, instead size and pointer  will be saved (as offset from Base symbol)     template <size_t Size>     constexpr explicit CString(const char (&literal)[Size])     {         if (!Size) new (this) CString;         else {                      // compute offset from `Base'             const intptr_t offset = literal - Base;             const intptr_t MaxOffset = uintptr_t(-1) >> (ConstSizeBits + 1);             const intptr_t MinOffset = uintptr_t(-1) << (sizeof(intptr_t)*8 - ConstSizeBits);             if (offset > MaxOffset || offset < MinOffset)                 runtime_error("CString offset in too large");              // compute low bits of size             constexpr size_t size = Size - 1;  // don't count terminating zero             constexpr uintptr_t short_size = size & ((1<<(ConstSizeBits - 1)) - 1);              // combine result             ptr = offset << ConstSizeBits | (short_size<<1) | 1;         }     }      // create copy of the string (by increasing reference count)     CString(const CString& other) noexcept : ptr{other.ptr}     {         if (ptr) {             if (! is_const())                 get_shared()->count++;         }     }      // move constructor just makes string empty     CString(CString&& other) noexcept : ptr{other.ptr} { other.ptr = 0; }       ~CString()     {         if (ptr && !is_const())         {             // free memory only in case if CString holds string in allocated memory             Shared *shared = get_shared();             if (--shared->count == 0)                 operator delete(shared);         }     }      // These functions used to create CString as result of calling printf-like function...     static CString vprintf(const char *fmt, va_list args);     static CString printf(const char *fmt, ...);      // Create CString as result of concatenation of given arguments     // (all shold be convertible to string_view).     template <typename... Args>     static CString concat(Args&&... args)     {             string_view parts[] = { args... };             size_t len = 0;             for (const string_view& s : parts)                 len += s.size();              return CString(len, [&parts](char *data){                             for(const string_view& s : parts)                                 data += s.copy(data, s.size());                         });     }      // Assign new value.     CString& operator=(const CString& other)     {             this->~CString();             return *new (this) CString(other);     }      // This function also handles case, when assigning "const char*" to CString,     // see comment in CString(string_view) above.     CString operator=(string_view str)     {         this->~CString();         return *new (this) CString(str);     }      // Assign string literal.     template <size_t Size> CString& operator=(const char (&literal)[Size])     {         this->~CString();         return *new (this) CString(literal);     }      // Get zero-terminated C-string representation.     const char *c_str() const noexcept     {         if (! ptr)  // empty string (returns pointer to nul-symbol)         {             return reinterpret_cast<const char*>(&ptr);         }         else if (! is_const())  // data in allocated memory         {             return get_shared()->data;         }         else {             return const_data(); // return string literal         }     }      // Return size of the stored string.     size_t size() const noexcept     {         if (! ptr)  // empty string         {             return 0;         }         else if (! is_const())  // data in allocated memory         {             return get_shared()->size;         }         else {             // decode `ptr' to lowest bits of string size and offset             const uintptr_t short_size = (ptr & ((1<<ConstSizeBits) - 1)) >> 1;             const char *start = const_data();             // start searching end of string             const char *end = &start[short_size];             while (*end) end += 1<<(ConstSizeBits - 1);             // compute length             return end - start;         }     }      // return `true' if CString is empty     bool empty() const noexcept { return !ptr; }      // access particular character by index     const char& operator[](int i) const noexcept { return c_str()[i]; }      // conversion to string_view     operator string_view() const noexcept { return string_view(c_str(), size()); } };  // these functions allow CString comparison with string_view or string literals template <typename T> bool operator==(const CString& s, T other) { return static_cast<string_view>(s) == static_cast<string_view>(other); } template <typename T> bool operator!=(const CString& s, T other) { return static_cast<string_view>(s) != static_cast<string_view>(other); } template <typename T> bool operator<(const CString& s, T other)  { return static_cast<string_view>(s) < static_cast<string_view>(other); } template <typename T> bool operator>(const CString& s, T other)  { return static_cast<string_view>(s) > static_cast<string_view>(other); } template <typename T> bool operator<=(const CString& s, T other) { return static_cast<string_view>(s) <= static_cast<string_view>(other); } template <typename T> bool operator>=(const CString& s, T other) { return static_cast<string_view>(s) >= static_cast<string_view>(other); }  template <typename T> bool operator==(T other, const CString& s) { return static_cast<string_view>(other) == static_cast<string_view>(s); } template <typename T> bool operator!=(T other, const CString& s) { return static_cast<string_view>(other) != static_cast<string_view>(s); } template <typename T> bool operator<(T other, const CString& s)  { return static_cast<string_view>(other) < static_cast<string_view>(s); } template <typename T> bool operator>(T other, const CString& s)  { return static_cast<string_view>(other) > static_cast<string_view>(s); } template <typename T> bool operator<=(T other, const CString& s) { return static_cast<string_view>(other) <= static_cast<string_view>(s); } template <typename T> bool operator>=(T other, const CString& s) { return static_cast<string_view>(other) >= static_cast<string_view>(s); }  bool operator==(const CString& s, const CString& other) { return static_cast<string_view>(s) == static_cast<string_view>(other); } bool operator!=(const CString& s, const CString& other) { return static_cast<string_view>(s) != static_cast<string_view>(other); } bool operator<(const CString& s, const CString& other)  { return static_cast<string_view>(s) < static_cast<string_view>(other); } bool operator>(const CString& s, const CString& other)  { return static_cast<string_view>(s) > static_cast<string_view>(other); } bool operator<=(const CString& s, const CString& other) { return static_cast<string_view>(s) <= static_cast<string_view>(other); } bool operator>=(const CString& s, const CString& other) { return static_cast<string_view>(s) >= static_cast<string_view>(other); }   ////////////////////////////// CString.cpp file //////////////////////////////////////  #include <stdio.h>  const char CString::Base[1] = "";  CString CString::vprintf(const char *fmt, va_list args) {     int len = vsnprintf(NULL, 0, fmt, args);     if (len <= 0) return CString(string_view());     return CString(len, [&](char *data){ vsnprintf(data, len + 1, fmt, args); }); }  CString CString::printf(const char *fmt, ...) {     va_list args;     va_start(args, fmt);     CString result = CString::vprintf(fmt, args);     va_end(args);     return result; }   /////////////////////// Usage examples ////////////////////////////////////////////////  int main() {     // create CString from literal     CString lit("1234");      // create CString by contatenating multiple strings     string_view sv = "ccc";     CString a = CString::concat("a", "bb", sv, lit);      // create CString by using printf-function     CString b = CString::printf("%d %s %d %s\n", int(lit.size()), lit.c_str(), a.size(), a.c_str());      // comparing CStrings     a == b;     a < b;     b >= a;     a == "xxx";     "yyy" != b;     a == sv;     sv != b;      string_view(a).data();      return 0; }  

Lightweight read-only string implementation (C++) [on hold]

In C++ currently we have few possibilities to work with strings:

1) by using plain old C-strings — unfortunately, we have penalty for getting length of string each time, and we should manually control life time of array, which actually contains data…

2) we can use std::string, but again, unfortunately this is not very efficient class: it’s relatively large (32 bytes on 64-bit platform) and it always copyes data;

3) modern C++ gives new opportunity: std::string_view class, which is quite effective, but unfortunately it doesn’t own strings, on which it references: again we should control life time of the containers in which strings really stored.

In Java or C# we have more reasonable solution, when class implementing strings divided on two:

  • StringBuilder which behaves like std::string and can be used to construct and edit strings;

  • String which is lightweight and always readonly, and can be used to access previously created strings — this class can be stored in arrays, passed in functions, etc…

I think, same solution might be perfect for C++, but this requires lot of work…

I want to present solution, which behaves like string in C# (in sence, that it is readonly and only can be created and reassigned). No counterpart, like StringBuffer was created, but my solution has very basic functions to create new strings.

I want to see some comments about my solution and suggestions how can I improve it.

Basic requirements when I design my own string-class implementation was following:

  • it should be very lightweight;

  • copying and passing by value should be almost free;

  • multiple intances of same string should share it’s representation (and memory);

  • strings cant be created from string literals and shouldn’t require memory allocation or copying in that case;

  • strings should be freely convertible to/from string_view class.

You can see the code here: https://coliru.stacked-crooked.com/a/ba8b05b14dbfbc52

#include <new> #include <string_view> #include <atomic> #include <stdexcept> #include <stdarg.h>  // Some implementation of class similar to `string_view' should be available in global namespace // (CString class requires this) using std::string_view;   // Class `CString' implements lightweight constant read-only string suitable // for storing in arrays, for passing by value, etc... // // Main essential properties of `CString' class are following: // //    * it has extremelly small size (1 pointer); // //    * copying (and passing by value) is almost free of cost; // //    * multiple instances of CString can share internal representation; // //    * if CString created from string literal it doesn't require //      neither memory allocation, nor data copying (so constant strings //      are really weightless). // // Some negative properties: // //    * size of stored string limited to 65536 bytes; // //    * nul-symbol can't be stored inside string; // //    * program can crash in runtime when constructing CString from string literal, //      if .rodata segment is larger than 8 MBytes (this is limit for 32-bit platform, //      for 64-bit platform limit is hardly noticeable); // //    * computing string size, when string was created from string literal and size //      is larger than 128 bytes, isn't performed in constant time: for each next //      128 bytes small additional penalty added (so computing size of large string //      created from string literals isn't free). // // This class can be modified, it represents only read-only strings, and can be // created in one of the following ways: // //    1) from literal string: CString text("some text..."); // //    2) from `string_view' and from const char* (implicitly, via string_view); // //    3) as result of calling static printf-like functions `printf' and `vprintf'; // //    4) as result of concatenation of any string-like objects convertible to string_view, //       via static concat(...) function; // //    5) as result of calling constructor with specifying desired string size and //       initializer function, which then creates string contents. // // CString class supports following operations: // //    * strings can be reassigned (but not modified); // //    * conversion to C-string or string_view (CString always stores zero-terminated //      representation of the string, nul-symbol can't be stored in the string); // //    * size of the string computed in constant time for most practical cases (see note above); // //    * characters can be accessed by index (implemented operator[]). // class CString { public:     typedef unsigned short size_type;  // first major limit: string sizes  private:     // This structure contains shared representation of the string, when string      // is stored in allocated memory.     struct Shared     {         std::atomic<unsigned short> count;  // second major limit: the number of shared copies         const size_type  size;              // size of the string (not including terminating zero)         char             data[1];          Shared(size_type size) : count{1}, size{size} {}     };      // This constant determines how many bits of variable `ptr' used for storing offset     // from `Base' to string literal, and how many bits used for encoding string literal length.     // Actually for string length ConstSizeBits-1 bits used (only lower bits of the length are     // stored, upper bits restored in runtime).     constexpr static const unsigned ConstSizeBits = 8;      // Address of this variable used to compute offset in .rodata segment, for storing string literals.     static const char Base[1];      // this variable might contain one of the three variants:     //     1) nullptr -- when CString contains empty string;     //     2) pointer to struct Shared -- when CString holds string in allocated memory;     //     3) offset between `Base' and string literal (offset in .rodata segment)     //        combined with lowest 7 bits of string length.     intptr_t ptr;      // returns `true' if current instance of CString stores string literal.     bool is_const() const noexcept        { return ptr & 1; }      Shared *get_shared() const noexcept   { return reinterpret_cast<Shared*>(ptr); }      // returns string literal address from offset stored in `ptr'     const char* const_data() const noexcept     {         intptr_t offset = ptr >> ConstSizeBits;         return reinterpret_cast<const char*>(offset + Base);     }      // function called in case, when offset can't be encoded in `ptr' (when offset is too large)     __attribute__((noreturn, noinline))     void runtime_error(const char *msg) const     {         throw std::runtime_error(msg);     }  public:     // create empty string (no memory allocation)     CString() noexcept : ptr{0} {}      // create string with specified size and initialize it by given functior (memory allocated)     template <typename Initializer> CString(size_t size, Initializer init)     {         if (!size) new (this) CString;         else {             if (size > size_type(-1))                 runtime_error("CString overflow");              Shared *shared = static_cast<Shared*>(operator new(size + sizeof(Shared)));             new (shared) Shared(size_type(size));             init(shared->data);             shared->data[size] = 0;             ptr = intptr_t(shared);         }     }      // create string from string_view class (memory allocated and string copy created)     explicit CString(string_view str)     {         new (this) CString(str.size(), [&str](char *data){ str.copy(data, str.size()); });     }      // Note: constructor like CString(const char *str) and operator= with same argument     // not implemented intentionally -- string should be created or assigned via intermediate     // string_view class. Existence of constructor or assigne operator with "const char *"     // argument prevents implementation of constructor or assign operators wich works with     // string literals (see below).      // create constant string from string literal (i.e. CString const_string("text")...)     // memory will not be allocated, instead size and pointer  will be saved (as offset from Base symbol)     template <size_t Size>     constexpr explicit CString(const char (&literal)[Size])     {         if (!Size) new (this) CString;         else {                      // compute offset from `Base'             const intptr_t offset = literal - Base;             const intptr_t MaxOffset = uintptr_t(-1) >> (ConstSizeBits + 1);             const intptr_t MinOffset = uintptr_t(-1) << (sizeof(intptr_t)*8 - ConstSizeBits);             if (offset > MaxOffset || offset < MinOffset)                 runtime_error("CString offset in too large");              // compute low bits of size             constexpr size_t size = Size - 1;  // don't count terminating zero             constexpr uintptr_t short_size = size & ((1<<(ConstSizeBits - 1)) - 1);              // combine result             ptr = offset << ConstSizeBits | (short_size<<1) | 1;         }     }      // create copy of the string (by increasing reference count)     CString(const CString& other) noexcept : ptr{other.ptr}     {         if (ptr) {             if (! is_const())                 get_shared()->count++;         }     }      // move constructor just makes string empty     CString(CString&& other) noexcept : ptr{other.ptr} { other.ptr = 0; }       ~CString()     {         if (ptr && !is_const())         {             // free memory only in case if CString holds string in allocated memory             Shared *shared = get_shared();             if (--shared->count == 0)                 operator delete(shared);         }     }      // These functions used to create CString as result of calling printf-like function...     static CString vprintf(const char *fmt, va_list args);     static CString printf(const char *fmt, ...);      // Create CString as result of concatenation of given arguments     // (all shold be convertible to string_view).     template <typename... Args>     static CString concat(Args&&... args)     {             string_view parts[] = { args... };             size_t len = 0;             for (const string_view& s : parts)                 len += s.size();              return CString(len, [&parts](char *data){                             for(const string_view& s : parts)                                 data += s.copy(data, s.size());                         });     }      // Assign new value.     CString& operator=(const CString& other)     {             this->~CString();             return *new (this) CString(other);     }      // This function also handles case, when assigning "const char*" to CString,     // see comment in CString(string_view) above.     CString operator=(string_view str)     {         this->~CString();         return *new (this) CString(str);     }      // Assign string literal.     template <size_t Size> CString& operator=(const char (&literal)[Size])     {         this->~CString();         return *new (this) CString(literal);     }      // Get zero-terminated C-string representation.     const char *c_str() const noexcept     {         if (! ptr)  // empty string (returns pointer to nul-symbol)         {             return reinterpret_cast<const char*>(&ptr);         }         else if (! is_const())  // data in allocated memory         {             return get_shared()->data;         }         else {             return const_data(); // return string literal         }     }      // Return size of the stored string.     size_t size() const noexcept     {         if (! ptr)  // empty string         {             return 0;         }         else if (! is_const())  // data in allocated memory         {             return get_shared()->size;         }         else {             // decode `ptr' to lowest bits of string size and offset             const uintptr_t short_size = (ptr & ((1<<ConstSizeBits) - 1)) >> 1;             const char *start = const_data();             // start searching end of string             const char *end = &start[short_size];             while (*end) end += 1<<(ConstSizeBits - 1);             // compute length             return end - start;         }     }      // return `true' if CString is empty     bool empty() const noexcept { return !ptr; }      // access particular character by index     const char& operator[](int i) const noexcept { return c_str()[i]; }      // conversion to string_view     operator string_view() const noexcept { return string_view(c_str(), size()); } };  // these functions allow CString comparison with string_view or string literals template <typename T> bool operator==(const CString& s, T other) { return static_cast<string_view>(s) == static_cast<string_view>(other); } template <typename T> bool operator!=(const CString& s, T other) { return static_cast<string_view>(s) != static_cast<string_view>(other); } template <typename T> bool operator<(const CString& s, T other)  { return static_cast<string_view>(s) < static_cast<string_view>(other); } template <typename T> bool operator>(const CString& s, T other)  { return static_cast<string_view>(s) > static_cast<string_view>(other); } template <typename T> bool operator<=(const CString& s, T other) { return static_cast<string_view>(s) <= static_cast<string_view>(other); } template <typename T> bool operator>=(const CString& s, T other) { return static_cast<string_view>(s) >= static_cast<string_view>(other); }  template <typename T> bool operator==(T other, const CString& s) { return static_cast<string_view>(other) == static_cast<string_view>(s); } template <typename T> bool operator!=(T other, const CString& s) { return static_cast<string_view>(other) != static_cast<string_view>(s); } template <typename T> bool operator<(T other, const CString& s)  { return static_cast<string_view>(other) < static_cast<string_view>(s); } template <typename T> bool operator>(T other, const CString& s)  { return static_cast<string_view>(other) > static_cast<string_view>(s); } template <typename T> bool operator<=(T other, const CString& s) { return static_cast<string_view>(other) <= static_cast<string_view>(s); } template <typename T> bool operator>=(T other, const CString& s) { return static_cast<string_view>(other) >= static_cast<string_view>(s); }  bool operator==(const CString& s, const CString& other) { return static_cast<string_view>(s) == static_cast<string_view>(other); } bool operator!=(const CString& s, const CString& other) { return static_cast<string_view>(s) != static_cast<string_view>(other); } bool operator<(const CString& s, const CString& other)  { return static_cast<string_view>(s) < static_cast<string_view>(other); } bool operator>(const CString& s, const CString& other)  { return static_cast<string_view>(s) > static_cast<string_view>(other); } bool operator<=(const CString& s, const CString& other) { return static_cast<string_view>(s) <= static_cast<string_view>(other); } bool operator>=(const CString& s, const CString& other) { return static_cast<string_view>(s) >= static_cast<string_view>(other); }   ////////////////////////////// CString.cpp file //////////////////////////////////////  #include <stdio.h>  const char CString::Base[1] = "";  CString CString::vprintf(const char *fmt, va_list args) {     int len = vsnprintf(NULL, 0, fmt, args);     if (len <= 0) return CString(string_view());     return CString(len, [&](char *data){ vsnprintf(data, len + 1, fmt, args); }); }  CString CString::printf(const char *fmt, ...) {     va_list args;     va_start(args, fmt);     CString result = CString::vprintf(fmt, args);     va_end(args);     return result; }   /////////////////////// Usage examples ////////////////////////////////////////////////  int main() {     // create CString from literal     CString lit("1234");      // create CString by contatenating multiple strings     string_view sv = "ccc";     CString a = CString::concat("a", "bb", sv, lit);      // create CString by using printf-function     CString b = CString::printf("%d %s %d %s\n", int(lit.size()), lit.c_str(), a.size(), a.c_str());      // comparing CStrings     a == b;     a < b;     b >= a;     a == "xxx";     "yyy" != b;     a == sv;     sv != b;      string_view(a).data();      return 0; }  

“Error creating directory: Read-only file system” – Can’t copy files to Pendrive

When i am tring to copy the folders or files to pendrive, I got error message “Error creating directory: Read-only file system”. I have tried to give permission to pendrive – chmod 777 * /media/”Name of Pendrive”, but i am facing the same issue. I am using Ubuntu 16.04

Porque o readonly ├ę valido no formul├írio?

Acabei de perceber que o readonly no input est├í dando como v├ílido, mesmo n├úo contendo nenhuma informa├ž├úo..

  • Porque isto acontece?
  • Como proceder para validar o input com este atributo?

Exemplo:

console.log(document.getElementById('RSPIUF').checkValidity())
<input type="text" id="RSPIUF" name="registration-step-personal-information-uf" class="form-control" aria-describedby="UF" placeholder="UF" readonly required>

What kinds of attacks are possible with credentials to a read-only Postgres user?

Assuming I implement the literal SQL-injection on an HTTP endpoint with a read-only user that limits execution time to e.g. some amount of seconds. What’s the worst that could happen? I know simple attacks could be just flooding simple queries. But is there another potential risk?

I already noticed some issues to mitigate:

  • The public role needs to be completely revoked of all permission and never granted anything.
  • Some functions might be more time and cpu intensive. I do wonder if there’s a way to limit the exposure to these other than a simple time out.
  • In general exposure to too many tables and columns.

Because this is a web service I control – I can constrain the contents of the SQL query, so that’s something I’d love to hear if there are functions, keywords or characters that I need to strip to make sure people are only making reasonable SELECT queries.

I realize this is somewhat of a vague request, but then again, security is a bit vague.

Read-only Access to Kibana/ESAAS

Allowing “GET” Operations only via a group is breaking kibana access. When user accesses kibana with credentials; the “discover” page is not displayed. The page “Localhost:5601/app/kibana#/discover?_g” fails repeatedly asking for credentials and the logs say they are failing due to “Post” operations being denied. So my question is why cant kibana use GET for searching logs? How to provide read onyl access to kibana/elastic? Is enabling POST operations ok? Can something be written with post which would alter data?