[Bug 8826] New: busybox reports zero exit code for invalid patch file

bugzilla at busybox.net bugzilla at busybox.net
Tue Mar 29 08:39:58 UTC 2016


https://bugs.busybox.net/show_bug.cgi?id=8826

            Bug ID: 8826
           Summary: busybox reports zero exit code for invalid patch file
           Product: Busybox
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P5
         Component: Other
          Assignee: unassigned at busybox.net
          Reporter: atrajeev at linux.vnet.ibm.com
                CC: busybox-cvs at busybox.net
  Target Milestone: ---

Created attachment 6406
  --> https://bugs.busybox.net/attachment.cgi?id=6406&action=edit
fix-to-error-out-for-invalid-patch

When given an invalid patch, busybox reports zero exit code even if the patch
is not applied.
With GNU patch, the behaviour is:

# patch < test.patch 
patch: **** Only garbage was found in the patch input.

With busybox patch, got the following output:

busybox patch < test.patch 
[root at localhost ~]# echo $?
0

Input patch file contents:
==================

cat test.patch:

-- test.c.org   2015-07-15 11:27:51.100000000 +0000
++ test.c       2015-07-15 11:28:11.189000000 +0000
@@ -1,8 +1,8 @@
 #include <stdio.h>
 int main()
 {
-       int i;
-       for (int j ; j <10; j++)
+       int i,j;
+       for (j ; j <10; j++)
        {
                printf("j is %d\n", j);
        }


and test.c file contents:

# cat test.c 
#include <stdio.h>
int main()
{
        int i;
        for (int j ; j <10; j++)
        {
                printf("j is %d\n", j);
        }

}


busybox code loops through patchlines and check for +++, switches state when
patches found. 

// state 0: Not in a hunk, look for +++.
// state 1: Found +++ file indicator, look for @@
// state 2: In hunk: counting initial context lines
// state 3: In hunk: getting body

state 2 implies code is getting into the hunk. 
Loop exits if patchline is empty

Adding a patch which has following changes:

- When state is 2, set patch_found to true ( implies a valid patch exists )
- when patchline is NULL,  ( i.e. when end of patch is reached ), set exitval
to 1 if:
                patchfile size is non-zero ( that means some content is there
in the patch file ) 
                and patch_found is false ( that means no valid patches were
found )

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the busybox-cvs mailing list