A
A
Alexey Yarkov2017-01-27 11:26:51
linux
Alexey Yarkov, 2017-01-27 11:26:51

Why does the program give the wrong result?

I'm probably sick of my stupid questions =) Let's continue!
In order not to write a long question, I will give a link:
https://github.com/yarkovaleksei/passgen/issues/1
The code is here:
https://github.com/yarkovaleksei/passgen/blob/mast...
I am now in local I'm trying to fix a branch, but there's such a trash ...
Here's how I'm trying to fix it:

if (length < 1)
  {
    while (isTyped != 1)
    {
      int t;
      char *ct = (char *)malloc(4); // хочу ограничить ввод числом 999
      printf("%s\n", _("Type in a password length"));
      scanf("%s", ct);

      if (isNumber(ct) == 1) // функция isNumber принимает char[], поэтому изврат с scanf("%s", ct)
      {
        t = atoi(ct); // конвертируем в число, если строка из цифр (убейте меня)
        if (t < 1) {
          isTyped = 0;
        } else {
          length = t;
          isTyped = 1;
        }
      } else {
        isTyped = 0;
      }
    }
  }

And now attention to the screenshot:
4d67935b89ef4c0a89dd95b61aaf56ef.png
WHAT THE FUCK? Why is the path to the file with Russian localization appended at the end?
Look, pliz, the entire repository. I feel like I'm the same m @ duck ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2017-01-27
@yarkov

Did you happen to forget the line ending character?

R
rPman, 2017-01-27
@rPman

FIG knows, there is an assumption in main.c
setlocale(LC_ALL, "");
#ifdef PACKAGE_LOCALE_DIR
bindtextdomain(PACKAGE_NAME, PACKAGE_LOCALE_DIR);
#else
#error Please use flag -DPACKAGE_LOCALE_DIR="locale"!
#endif
textdomain(PACKAGE_NAME);
some of this gives extra text to stdout the path to localization, but it is cached, caches are reset upon program completion

1
15432, 2017-01-27
@15432

An overflow occurs, scanf reads the entire line up to the newline character, but the buffer is only 4 bytes, and the data is overwritten beyond the buffer. Apparently, the file name is stored further, which is displayed. It is necessary to use safe scanf (in Windows it's scanf_s, in Linux I don't know).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question