Re: scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-11-03 Thread Michal Marek
Dne 2.11.2016 v 19:30 Masahiro Yamada napsal(a):
> 2016-11-03 2:38 GMT+09:00 SF Markus Elfring :
> +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {

 Rather than scatter fragile magic numbers, like 10, throughout the
 code, if you're hell-bent on checking for printf errors you could
 write a little wrapper function that hid the magic number and bundled
 up the errno stuff.
>>>
>>>
>>> BTW, how the magic number "10" was calculated?
>>
>> Does the passed format string indicate how many characters should be
>> printed at least?
> 
> So, the check is a bit compromised.
> The printf() should print at lease 10 characters.
> If "target" or "cmdline" is not NULL, it should print more.

printf() / fprintf() return a negative value if an error such as ENOSPC
occurs. So just check for < 0 and preferably use a wrapper.

Michal



Re: scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-11-03 Thread Michal Marek
Dne 2.11.2016 v 19:30 Masahiro Yamada napsal(a):
> 2016-11-03 2:38 GMT+09:00 SF Markus Elfring :
> +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {

 Rather than scatter fragile magic numbers, like 10, throughout the
 code, if you're hell-bent on checking for printf errors you could
 write a little wrapper function that hid the magic number and bundled
 up the errno stuff.
>>>
>>>
>>> BTW, how the magic number "10" was calculated?
>>
>> Does the passed format string indicate how many characters should be
>> printed at least?
> 
> So, the check is a bit compromised.
> The printf() should print at lease 10 characters.
> If "target" or "cmdline" is not NULL, it should print more.

printf() / fprintf() return a negative value if an error such as ENOSPC
occurs. So just check for < 0 and preferably use a wrapper.

Michal



Re: scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-11-02 Thread Masahiro Yamada
2016-11-03 2:38 GMT+09:00 SF Markus Elfring :
 +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {
>>>
>>> Rather than scatter fragile magic numbers, like 10, throughout the
>>> code, if you're hell-bent on checking for printf errors you could
>>> write a little wrapper function that hid the magic number and bundled
>>> up the errno stuff.
>>
>>
>> BTW, how the magic number "10" was calculated?
>
> Does the passed format string indicate how many characters should be
> printed at least?

So, the check is a bit compromised.
The printf() should print at lease 10 characters.
If "target" or "cmdline" is not NULL, it should print more.




-- 
Best Regards
Masahiro Yamada


Re: scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-11-02 Thread Masahiro Yamada
2016-11-03 2:38 GMT+09:00 SF Markus Elfring :
 +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {
>>>
>>> Rather than scatter fragile magic numbers, like 10, throughout the
>>> code, if you're hell-bent on checking for printf errors you could
>>> write a little wrapper function that hid the magic number and bundled
>>> up the errno stuff.
>>
>>
>> BTW, how the magic number "10" was calculated?
>
> Does the passed format string indicate how many characters should be
> printed at least?

So, the check is a bit compromised.
The printf() should print at lease 10 characters.
If "target" or "cmdline" is not NULL, it should print more.




-- 
Best Regards
Masahiro Yamada


Re: scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-11-02 Thread SF Markus Elfring
>>> +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {
>>
>> Rather than scatter fragile magic numbers, like 10, throughout the
>> code, if you're hell-bent on checking for printf errors you could
>> write a little wrapper function that hid the magic number and bundled
>> up the errno stuff.
> 
> 
> BTW, how the magic number "10" was calculated?

Does the passed format string indicate how many characters should be
printed at least?

Regards,
Markus


Re: scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-11-02 Thread SF Markus Elfring
>>> +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {
>>
>> Rather than scatter fragile magic numbers, like 10, throughout the
>> code, if you're hell-bent on checking for printf errors you could
>> write a little wrapper function that hid the magic number and bundled
>> up the errno stuff.
> 
> 
> BTW, how the magic number "10" was calculated?

Does the passed format string indicate how many characters should be
printed at least?

Regards,
Markus


Re: [PATCH 09/10] scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-11-02 Thread Masahiro Yamada
2016-10-29 8:42 GMT+09:00 Jim Davis :
> On Fri, Oct 28, 2016 at 1:40 AM, SF Markus Elfring
>  wrote:
>
>> +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {
>
> Rather than scatter fragile magic numbers, like 10, throughout the
> code, if you're hell-bent on checking for printf errors you could
> write a little wrapper function that hid the magic number and bundled
> up the errno stuff.


BTW, how the magic number "10" was calculated?




-- 
Best Regards
Masahiro Yamada


Re: [PATCH 09/10] scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-11-02 Thread Masahiro Yamada
2016-10-29 8:42 GMT+09:00 Jim Davis :
> On Fri, Oct 28, 2016 at 1:40 AM, SF Markus Elfring
>  wrote:
>
>> +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {
>
> Rather than scatter fragile magic numbers, like 10, throughout the
> code, if you're hell-bent on checking for printf errors you could
> write a little wrapper function that hid the magic number and bundled
> up the errno stuff.


BTW, how the magic number "10" was calculated?




-- 
Best Regards
Masahiro Yamada


Re: scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-10-30 Thread SF Markus Elfring
> But what would you expect printf error checking to tell a user?

I wonder that the error detection and corresponding exception handling
was not corrected for the affected source files of build-time tools so far.
https://www.securecoding.cert.org/confluence/display/c/EXP12-C.+Do+not+ignore+values+returned+by+functions

Regards,
Markus


Re: scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-10-30 Thread SF Markus Elfring
> But what would you expect printf error checking to tell a user?

I wonder that the error detection and corresponding exception handling
was not corrected for the affected source files of build-time tools so far.
https://www.securecoding.cert.org/confluence/display/c/EXP12-C.+Do+not+ignore+values+returned+by+functions

Regards,
Markus


Re: [PATCH 09/10] scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-10-28 Thread Jim Davis
On Fri, Oct 28, 2016 at 1:40 AM, SF Markus Elfring
 wrote:

> +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {

Rather than scatter fragile magic numbers, like 10, throughout the
code, if you're hell-bent on checking for printf errors you could
write a little wrapper function that hid the magic number and bundled
up the errno stuff.

But what would you expect printf error checking to tell a user?
Perhaps that he or she ran out of disk space, but that's going to be
painfully obvious anyway in almost every case.

-- 
Jim


Re: [PATCH 09/10] scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-10-28 Thread Jim Davis
On Fri, Oct 28, 2016 at 1:40 AM, SF Markus Elfring
 wrote:

> +   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {

Rather than scatter fragile magic numbers, like 10, throughout the
code, if you're hell-bent on checking for printf errors you could
write a little wrapper function that hid the magic number and bundled
up the errno stuff.

But what would you expect printf error checking to tell a user?
Perhaps that he or she ran out of disk space, but that's going to be
painfully obvious anyway in almost every case.

-- 
Jim


[PATCH 09/10] scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-10-28 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 28 Oct 2016 09:29:59 +0200

A return value was not checked from a call of the function "printf".

This issue was detected also by using the Coccinelle software.


Add a bit of exception handling there.

Signed-off-by: Markus Elfring 
---
 scripts/basic/fixdep.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index f5ff6eea..911347a 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -132,7 +132,12 @@ static void usage(void)
  */
 static void print_cmdline(void)
 {
-   printf("cmd_%s := %s\n\n", target, cmdline);
+   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {
+   int code = errno;
+
+   perror("fixdep: print_cmdline");
+   exit(code);
+   }
 }
 
 /*
-- 
2.10.1



[PATCH 09/10] scripts/basic/fixdep: Complete error handling in print_cmdline()

2016-10-28 Thread SF Markus Elfring
From: Markus Elfring 
Date: Fri, 28 Oct 2016 09:29:59 +0200

A return value was not checked from a call of the function "printf".

This issue was detected also by using the Coccinelle software.


Add a bit of exception handling there.

Signed-off-by: Markus Elfring 
---
 scripts/basic/fixdep.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index f5ff6eea..911347a 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -132,7 +132,12 @@ static void usage(void)
  */
 static void print_cmdline(void)
 {
-   printf("cmd_%s := %s\n\n", target, cmdline);
+   if (printf("cmd_%s := %s\n\n", target, cmdline) < 10) {
+   int code = errno;
+
+   perror("fixdep: print_cmdline");
+   exit(code);
+   }
 }
 
 /*
-- 
2.10.1