8
[-] MarekKnapek@programming.dev 4 points 8 months ago

The main language of the app was English. The user could change it to German, French, Russian, Chinese, Spanish, etc. But sometimes the translation was not complete. Sometimes some plug-in was not translated. We used string IDs to identify various texts. Sometimes the ID pointed to the translated text, sometimes not, thus English version of that text was used instead.

Also I reported the bug in the visual style to Microsoft. They refused to fix it and said something like "don't do that".

[-] MarekKnapek@programming.dev 4 points 8 months ago

Win32 MFC desktop application, should be able to run continuously unsupervised for days or weeks. When I log in via RDP it crashed. Yes, just in that moment. In the end I figured it out.

MFC supports multiple visual styles, such as classic Windows, few Office versions and few more. We used feature for loading (possibly translated) strings (resource) from various DLLs. First from a currently active plug-in DLL, if the string was not there, then from a sub-system DLL, if it was not there then from main EXE. Plus there was some logic about translation and fallback to English in case of missing or not up-to-date translation. The cause was in one of the MFC visual styles, it changed a global variable related to that string loading thing for a short duration of time, then changed it back. It was only in one of the styles and there was no need to change it, the code could just load the value and use it as a parameter to a function that needed it. Our code in a different thread failed to load a string and threw an exception. Cross a COM interface boundary. Every COM method is decorated by a bunch of macros our senior engineer didn't understand and was not willing to learn. One of the macros was noexcept. Thus an exception being thrown cross an noexcept boundary crashed our app.

[-] MarekKnapek@programming.dev 6 points 10 months ago

No! One code point could be encoded by up to 4 UTF-8 code units, not glyph. Glyphs do not map to code points one to one. One glyph could be encoded by more than one code point (and each code point could be encoded by more than one code unit). Code points are Unicode thing, code units are Unicode encoding thing, glyphs are font+Unicode thing. For example the glyph á might be single code point or two code points. Single code point because this is common letter in some languages, and was used in computers before Unicode was invented, two code points because this might be the base letter a followed by an diacritic combining mark. Not all diacritic letters have single code point variant. Also emojis, they are single glyph but multiple code points, for example skin tone modifier for various faces emojis, or male+female characters combined into single glyph forming a family glyph. Also country flags are single glyph, but multiple code points. Unicode is BIG, there are A LOT of stuff in it. For example sorting based on users language, conversion to upper/lower case is also not trivial (google the turkish i).

[-] MarekKnapek@programming.dev 4 points 2 years ago

You have stack buffer out of bounds write. On line 52 you declare h an array of 70 unsigned ints. On line 57 you store reference to such array. Later, on line 35 you write out of bounds, one element past end of the array. The _SPR_history[i] writes to _SPR_history[70]. Created an issue: https://github.com/X64X2/sh/issues/1

[-] MarekKnapek@programming.dev 4 points 2 years ago

Doesn't depend on programming language but something with visual debugger. You know that stuff when you can see current line of your source code highlighted, press a key to step into, step over and so on. You can see values inside your variables. You can also change your variables mid-run right form the debugger.

Because you spend 20% of your time writing bugs and the other 80% debugging them. At least make it pleasant experience (no printf-style debugging).

Back in the day I was using Turbo Pascal, Delphi, Visual Basic, C#, Java, PHP with Zend, Java Script, today I'm using Visual C++.

24
32 MiB Working Sets on a 64 GiB machine (randomascii.wordpress.com)
[-] MarekKnapek@programming.dev 5 points 3 years ago

The interview starts ... the interviewer asks me "Tell me about yourself." ... I respond "Did you receive my CV? I put all important details about me ... right there. What questions do you have about my past jobs?" The interviewer encourages me again to tell him about myself, my past projects, etc. ... Me: Awkward silence. ... Me to myself: Dafuq? Should I read the CV from top to bottom OR WHAT?

0
[-] MarekKnapek@programming.dev 12 points 3 years ago

std::vector::reserve + std::vector::push_back in loop is sub-optimal, because push_back needs to check for re-allocation, but that never comes.

std::vector::resize + std::vector::operator[] in loop is also sub-optimal, because resize default-initializes all elements only to be overwritten soon anyway.

This article's author suggests push_back_unchecked.

I suggest std::vector::insert with pair of random access iterators with custom dereference operator that does the "transform element" or "generate element" functionality. The standard will have resize_and_overwrite hopefully soon.

Moar discussion:

https://codingnest.com/the-little-things-the-missing-performance-in-std-vector/

https://twitter.com/horenmar_ctu/status/1695823724673466532

https://twitter.com/horenmar_ctu/status/1695331079165489161

https://www.reddit.com/r/cpp/comments/162tohr/the_little_things_the_missing_performance_in/

https://www.reddit.com/r/cpp/comments/162tohr/the_little_things_the_missing_performance_in/jy21hgd/

https://twitter.com/basit_ayantunde/status/1644895468399337473

https://twitter.com/MarekKnapek/status/1645272474517422081

https://www.reddit.com/r/cpp/comments/cno9ep/improving_stdvector/

52
[-] MarekKnapek@programming.dev 5 points 3 years ago

Another alternative to C++ exceptions (instead of return code) is to use global (or thread local) variable. This is exactly what errno that C and POSIX are using or GetLastError what Windows is using. Of course, this has its own pros and cons.

[-] MarekKnapek@programming.dev 36 points 3 years ago

Makes sense, how would you represent floor(1e42) or ceil(1e120) as integer? It would not fit into 32bit (unsigned) or 31bit (signed) integer. Not even into 64bit integer.

15

Wanna encrypt something? I implemented AES-256 (aka military grade encryption) from scratch in C89, compiled it into WebAssembly and published it on web at https://marekknapek.github.io/crypt/ You need web browser that supports writing files to your disk from JavaScript.

[-] MarekKnapek@programming.dev 28 points 3 years ago

Oversimplified:

  • You have your current OS, text editor, compiler.
  • You write code of the new improved OS using your current OS, text editor.
  • You compile the code (text file), compilation yields the new OS or the new kernel (binary file).
  • You replace (overwrite) your current kernel by the new kernel (current OS by new OS). This is possible, because while the OS is running it is in RAM not touching the disk.
  • You restart.
  • BIOS loads the new OS from disk to RAM and executes it.
  • tada.wav

More questions:

  • How to update BIOS? Answer: The same.
  • How the first OS, text editor and compiler were created? Answer: The same. Using more primitive OS, text editor and compiler each step into the past. At the beginning there were toggle switches, punch cards, punch ribbon strips or similar.

The same style of question would be: How to create a hammer if in order to create a hammer you need a hammer? How was the first hammer created? Answer: By more primitive hammer, or something that is no hammer, but almost works as a hammer.

For more info read about bootstrapping compilers. Or trusting the trust by Ken Thompson.

[-] MarekKnapek@programming.dev 5 points 3 years ago

Oh I forgot another line of defense / basic security mitigation. If a server produces an access token (such as JWT or any other old school cookie / session ID), pair it with an IP address. So in case of cookie theft, the attacker cannot use this cookie from his computer (IP address). If the IP changes (mobile / WiFi / ADSL / whatever), the legitimate user should log-in again, now storing two auth cookies. In case of another IP change, no problemo, one of the stored cookies will work. Of course limit validity of the cookie in time (lets, say, keep it valid only for a day or for a week or so).

[-] MarekKnapek@programming.dev 7 points 3 years ago

So what happened:

  • Someone posted a post.
  • The post contained some instruction to display custom emoji.
  • So far so good.
  • There is a bug in JavaScript (TypeScript) that runs on client's machine (arbitrary code execution?).
  • The attacker leveraged the bug to grab victim's JWT (cookie) when the victim visited the page with that post.
  • The attacker used the grabbed JWTs to log-in as victim (some of them were admins) and do bad stuff on the server.

Am I right?

I'm old-school developer/programmer and it seems that web is peace of sheet. Basic security stuff violated:

  • User provided content (post using custom emojis) caused havoc when processing (doesn't matter if on server or on client). This is lack of sanitization of user-provided-data.
  • JavaScript (TypeScript) has access to cookies (and thus JWT). This should be handled by web browser, not JS. In case of log-in, in HTTPS POST request and in case of response of successful log-in, in HTTPS POST response. Then, in case of requesting web page, again, it should be handled in HTTPS GET request. This is lack of using least permissions as possible, JS should not have access to cookies.
  • How the attacker got those JWTs? JavaScript sent them to him? Web browser sent them to him when requesting resources form his server? This is lack of site isolation, one web page should not have access to other domains, requesting data form them or sending data to them.
  • The attacker logged-in as admin and caused havoc. Again, this should not be possible, admins should have normal level of access to the site, exactly the same as normal users do. Then, if they want to administer something, they should log-in using separate username + password into separate log-in form and display completely different web page, not allowing them to do the actions normal users can do. You know, separate UI/applications for users and for admins.

Am I right? Correct me if I'm wrong.

Again, web is peace of sheet. This would never happen in desktop/server application. Any of the bullet points above would prevent this from happening. Even if the previous bullet point failed to do its job. Am I too naïve? Maybe.

Marek.

1

Hi all, I implemented yet another on-line cryptographic hash functions calculator. It is written in C, compiled into WebAssembly and is running inside your web browser (nothing is sent to the server). The calculator: https://marekknapek.github.io/hash, web page source code: https://github.com/MarekKnapek/MarekKnapek.github.io, C source code: https://github.com/MarekKnapek/mk_clib.

3

Hi all, I implemented yet another on-line cryptographic hash functions calculator. It is written in C, compiled into WebAssembly and is running inside your web browser (nothing is sent to the server). The calculator: https://marekknapek.github.io/hash, web page source code: https://github.com/MarekKnapek/MarekKnapek.github.io, C source code: https://github.com/MarekKnapek/mk_clib.

1

Hi all, I implemented yet another on-line cryptographic hash functions calculator. It is written in C, compiled into WebAssembly and is running inside your web browser (nothing is sent to the server). The calculator: https://marekknapek.github.io/hash, web page source code: https://github.com/MarekKnapek/MarekKnapek.github.io, C source code: https://github.com/MarekKnapek/mk_clib.

view more: next ›

MarekKnapek

0 post score
0 comment score
joined 3 years ago